tags:

views:

53

answers:

1

Hi, I need advance. 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.

A: 

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.

Moutaz Shams