Tessnet2 System.AccessViolationException

968 Views Asked by At

Hi i am trying to get Tessnet2 to work. My code is

Bitmap image = new Bitmap(@"C:\Users\Eric\Desktop\Text Pictures\Oil0.bmp");

tessnet2.Tesseract ocr = new tessnet2.Tesseract();

ocr.SetVariable("tessedit_char_whitelist", "0123456789"); 

ocr.Init(@"C:\tessdata", "eng", false); 

List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty); // Error occurs here

foreach (tessnet2.Word word in result)
     Console.WriteLine("{0} : {1}", word.Confidence, word.Text);

When i run it i get the error "System.AccessViolationException" at List result = ocr.DoOCR(image, Rectangle.Empty);

I am using .net 3.5 and i got really no idea whats wrong here. Any suggestions?

4

There are 4 best solutions below

0
On

Remove the ocr.SetVariable method

Also, don't point the path to the tessdata folder itself.

If you do want only to use numeric chars, you can use this code:

Bitmap image = new Bitmap(@"C:\Users\Eric\Desktop\Text Pictures\Oil0.bmp");

tessnet2.Tesseract ocr = new tessnet2.Tesseract();



ocr.Init(@"C:\DontPointToTessDataDirectly", "eng", true); 

List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty); // Error occurs here

foreach (tessnet2.Word word in result)
     Console.WriteLine("{0} : {1}", word.Confidence, word.Text);
0
On

Try to save your Oil0.bmp to .jpg with small resolution and file size quality. I had this problem before. Problem was in picture file. After resizing file to 250x100px up to 14Kb, mistake disappeared)

0
On

1.make sure if you're using tessnet2 that you download the correct language files.You should use English language data for Tesseract (2.00 and up) and not the English language data for Tesseract 3.01 version.Download correct data from below link. https://code.google.com/p/tesseract-ocr/downloads/list

2.If you installed any tesseract-ocr-setup.exe means your program always refer tessdata file under C:\Program Files\Tesseract-OCR\tessdata location because setup Installation time it will create a environment variable TESSDATA_PREFIX with value **C:\Program Files\Tesseract-OCR** .To solve this issue uninstall setup and remove environment variable or keep your tessdata files under C:\Program Files\Tesseract-OCR\tessdata location.

0
On

It shows this error, you clean your solution and rebuild it and it will work. There is nothing wrong with the code. Verify your app.config just a caution.