0

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!

yohan.jayarathna
  • 3,423
  • 13
  • 56
  • 74
  • But tessnet is already a wrapper around tessaract in managed code. It also contains DoOCR method which can be used without importing. So what are you trying to do? What is a Word class in your code? – EvgK Feb 08 '11 at 12:41

2 Answers2

2

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);
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

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

Mubashir Khan
  • 1,464
  • 1
  • 12
  • 17