charlesw / tesseract

A .Net wrapper for tesseract-ocr
Apache License 2.0
2.25k stars 741 forks source link

OCR not reading Images Captured from Webcam #74

Closed rajasajidmanzoor closed 10 years ago

rajasajidmanzoor commented 10 years ago

Hello. I am trying to capture images via webcam and then read it using OCR but OCR is not reading them. I have also bought an HD 1080p anti flare and anti noise web cam but sill it is not reading Text and number. I am trying to read from following images. 635274050225667315 ![Uploading 635274052466609107.pn 635274061914640258 635274072532590700 635274072532590700 capture1

g . . .]()

But it is not reading all images. I also tried using Grey scale images but still issue persists. Please tell me how can i read these images or also suggest me any image processing techniques if needed..

Sajid

charlesw commented 10 years ago

I got reasonable results after I (manually) cropped the image so the border isn't included and then binarized the image (using BinarizeOtsuAdaptiveThreshold, with params img.Width / 5, img.Height / 5, 10, 10, 0.1 as previously mentioned in #71).

You will of course need to find a way to crop the image automatically maybe either doing some edge detection or page analysis.

rajasajidmanzoor commented 10 years ago

hmm. thanks. Can you please share a code example for BinarizeOtsuAdaptiveThreshold and also please tell me where should i use BinarizeOtsuAdaptiveThreshold..

Thanks

charlesw commented 10 years ago

Something like this:

using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
    using (var img = Pix.LoadFromFile(testImagePath)) {
        using (var binarizedImg = img.BinarizeOtsuAdaptiveThreshold(img.Width / 5, img.Height / 5, 10, 10, 0.1F)) {
            binarizedImg.Save("Binarized-test.png", ImageFormat.Png);

            using (var page = engine.Process(binarizedImg)) {
                var text = page.GetText();

                // whatever

            }
        }
    }
}

Where/How to use this is really going to depend on how you've written your application and what other processing you plan on doing.

charlesw commented 10 years ago

Note that the testImagePath must be a path to a 8 BPP (bit's per pixel) image. Binarization WILL fail if it's anything else.

rajasajidmanzoor commented 10 years ago

ok. How can i check that image in 8 bits per pixel image in c# and if it is not a 8 BPP image than how can i make it 8BPP

thanks

charlesw commented 10 years ago

Your after the Depth property which will need to equal 8 in this case. As for converting a 32-bit image (or other source) you'll probably want to use a Quantization method unfortunately I haven't wrapped these methods from Leptonica at this time. I've added issue #75 however can't say when I'll get to this. Another option may be to capture the images as 8-bit images if possible.

rajasajidmanzoor commented 10 years ago

hello Can you please describe what is Quantization method. I tried to convert an image to Bit using following method. http://codingresolved.com/discussion/2185/save-png-image-as-8bit-format-in-c and then applied binarization as you told me above. but it is not reading text from image. the image that i have used is (before converting to 32 bit see below image) 32bit before converting to 8 bit it only reads last line.

See below image after conversion to 8 bit. Not a single word has been read after converting to 8 bit.

8bit

charlesw commented 10 years ago

Did you also crop it, this is the image I ended up processing that worked: binarized-test

rajasajidmanzoor commented 10 years ago

Hello Please confirm how did you achieved this result. i performed following trick to get the second image http://codingresolved.com/discussion/2185/save-png-image-as-8bit-format-in-c

charlesw commented 10 years ago

I just opened it in my favorite picture editor (Paint.Net in this case), cropped the image and saved it as a png file with 256 colours (8 bpp) and then fed that to the previously mentioned routine.

rajasajidmanzoor commented 10 years ago

hmm. Ok thanks But if possible can you please share a code example for pixOctreeColorQuant so that i get a start. I know that i am disturbing you and taking a lot of your time but i don't have any other way to sort out. I will be thankful to you if you help me.

charlesw commented 10 years ago

OK, given you time limits here's what I would do:

  1. Forget about BinarizeOtsuAdaptiveThreshold for now (this removes the 8 BPP requirement)
  2. Run an analyse over the image, hopefully it identifies the characters on the plate.
  3. Iterate over the result and build a bounding box that contains the center characters (see sample).
  4. Crop image to bounding box.
  5. OCR the cropped image

If step 2 doesn't come up with any results you could try a fallback of just cropping the edges and checking the results however this is really unreliable but might be better than nothing.

rajasajidmanzoor commented 10 years ago

ok. but there where is sample. Are you talking about the samples included in Wrapper..

charlesw commented 10 years ago

Yes, specifically the console one.

On Wed, Feb 12, 2014 at 8:44 PM, sajiddesigner notifications@github.comwrote:

ok. but there where is sample. Are you talking about the samples included in Wrapper..

Reply to this email directly or view it on GitHubhttps://github.com/charlesw/tesseract/issues/74#issuecomment-34852981 .

rajasajidmanzoor commented 10 years ago

and also please confirm that which file format is best for optimum results in tesseract. JPG, PNG, TIFF or Gif.