开发者

C# .net wrapper for tessnet

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!


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);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜