tessnet 的 C# .net 包装器

发布于 2024-10-16 13:15:39 字数 415 浏览 8 评论 0原文

我尝试为 tessnet OCR 库编写包装器。我收到一条错误消息“无法封送‘返回值’:无法封送通用类型。”对于此代码部分,

List<Word> k = OCRWrapper.DoOCR(new Bitmap(@"C:\Data\pdf2image\auto.png"), new Rectangle(0, 0, 55, 27));

我的包装类

class OCRWrapper
{
    [DllImport("TrueMarble.dll")]
    public static extern List<Word> DoOCR(Bitmap b, Rectangle rec);
}

请帮助我,任何人都可以指导我编写此代码

谢谢!

I try to write wrapper for tessnet OCR library. I am getting an error saying "Cannot marshal 'return value': Generic types cannot be marshaled." for this code section

List<Word> k = OCRWrapper.DoOCR(new Bitmap(@"C:\Data\pdf2image\auto.png"), new Rectangle(0, 0, 55, 27));

My wrapper class is

class OCRWrapper
{
    [DllImport("TrueMarble.dll")]
    public static extern List<Word> DoOCR(Bitmap b, Rectangle rec);
}

please help me, can any one guide me to write this code

Thanx!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纸伞微斜 2024-10-23 13:15:39

你走错了路,Tessnet 已经是 Tesseract 的托管类包装器。您不使用 [DllImport],只需添加对程序集的引用并直接使用类。示例代码和程序集下载位于此处

Bitmap image = new Bitmap("eurotext.tif");
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "0123456789"); // If digit only
ocr.Init(@"c:\temp", "fra", false); // To use correct tessdata

List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);
foreach (tessnet2.Word word in result)
    Console.WriteLine("{0} : {1}", word.Confidence, word.Text);

You are on the wrong track with this, Tessnet already is a managed class wrapper around Tesseract. You don't use [DllImport], just add a reference to the assembly and use the classes directly. Sample code and assembly download is available here.

Bitmap image = new Bitmap("eurotext.tif");
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "0123456789"); // If digit only
ocr.Init(@"c:\temp", "fra", false); // To use correct tessdata

List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);
foreach (tessnet2.Word word in result)
    Console.WriteLine("{0} : {1}", word.Confidence, word.Text);
兮子 2024-10-23 13:15:39

泛型类型无法编组,因为它们是 .NET 原生的。使用单词数组代替

Generic types could not be marshalled as they are native to .NET. use array of word instead

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文