简体   繁体   中英

Assistance with Tessnet2

I need advice. I am trying to use Tessnet2 lib to recognize text of image.

Image consist a string with five characters(chars and digit).

  1. I downloaded lib from http://www.pixel-technology.com/freeware/tessnet2/ .

  2. Add refrence on this lib in my project.

  3. Then I downloaded language data definition file (from http://code.google.com/p/tesseract-ocr/downloads/list)and put it in tessdata directory.

The data definition file is in same directory as exe file.

Here is my code:

try
{ //download image from server
    System.Net.WebRequest request =
        System.Net.WebRequest.Create(
        textBox1.Text);
    System.Net.WebResponse response = request.GetResponse();
    System.IO.Stream responseStream =
        response.GetResponseStream();
    Bitmap  image = new Bitmap(responseStream);

    pictureBox1.Image =image;

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

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

    ocr.Init(@"C:\Users\Tan\Documents\Visual Studio 2010\Projects\TestProject\bin\Release", "eng", false); // To use correct tessdata

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

}
catch (System.Net.WebException)
{
    MessageBox.Show("There was an error opening the image file."
       + "Check the URL");
}

Problem is, if I invoke this code, app is closed. I get nothing error message. I don't why. Can anybody help me? Thank you.

Have you installed Tesseract 3 ?

If so uninstall it and remove the environment variable named something with tessdata, and restart.

If someone still wants to know what to do in this case:

I had the same problem and i could fix it with help of this link and passing the tessdata directory to the init functions. (There is one in the main function and two in OCR class.) The link mentioned above helped me as i had to download the v2.00 language files instead of the latest v3.0x ...

Best regards

I think the error in ocr.Init line, be sure the path is correct. Also try to pass null as I remember it does not need the path because you always have to put all data in tessdata directory in the same folder which contains your exe file.

Try to use Debug solution configuration in Visual Studio against Release solution configuration. Some debug information are not included in Release configuration. And shoots bugs like that.

The problem lies with your ocr.Init(). Make sure that directory "C:\\Users\\Tan\\Documents\\Visual Studio 2010\\Projects\\TestProject\\bin\\Release" contains the required files:

eng.DangAmbigs

eng.freq-dawg

eng.inttemp

eng.normproto

eng.pffmtable

eng.unicharset

eng.user-words

eng.word-dawg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM