Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recognize a number from an image

I'm trying to write an application to find the numbers inside an image and add them up.

How can I identify the written number in an image?

enter image description here

There are many boxes in the image I need to get the numbers in the left side and sum them to give total. How can I achieve this?

Edit: i did a java tesseract ocr on the image but i didnt get any correct results. how can i train it?

also

i did a edge detection i got this:

enter image description here

like image 977
Hash Avatar asked Apr 20 '15 10:04

Hash


People also ask

How can I identify text in an image?

To extract text from image, we introduce a free online OCR (Optical Character Recognition) service. Upload a photo to the image to text converter online, click on convert and get your text file instantly.

How do I read a JPEG number?

jpg? The first letter P stands for picture. The second to fourth number/letter represent the date the image is taken. The second number/letter represent month (1-9 for Jan-Sep, ABC for Oct-Dec).


1 Answers

You will most likely need to do the following:

  1. Apply the Hough Transform algorithm on the entire page, this should should yield a series of page sections.

  2. For each section you get, apply it again. If the current section yielded 2 elements, then you should be dealing with a rectangle similar to the above.

  3. Once that you are done, you can use an OCR to extract the numeric value.

In this case, I would recommend you take a look at JavaCV (OpenCV Java Wrapper) which should allow you to tackle the Hough Transform part. You would then need something akin to Tess4j (Tesseract Java Wrapper) which should allow you to extract the numbers you are after.

As an extra note, to reduce the amount of false positives, you might want to do the following:

  1. Crop the image if you are certain that certain coordinates will never contain data you are after. This should give you a smaller picture to work with.

  2. It might be wise to change the image to grey scale (assuming you are working with a colour image). Colours can have a negative impact on the OCR's ability to resolve the image.

EDIT: As per your comment, given something like this:

+------------------------------+ |                   +---+---+  | |                   |   |   |  | |                   +---+---+  | |                   +---+---+  | |                   |   |   |  | |                   +---+---+  | |                   +---+---+  | |                   |   |   |  | |                   +---+---+  | |                   +---+---+  | |                   |   |   |  | |                   +---+---+  | +------------------------------+ 

You would crop the image so that your remove the area which does not have relevant data (the part on the left) by cropping the image, you would get something like so:

+-------------+ |+---+---+    | ||   |   |    |  |+---+---+    | |+---+---+    | ||   |   |    | |+---+---+    | |+---+---+    | ||   |   |    | |+---+---+    | |+---+---+    | ||   |   |    | |+---+---+    | +-------------+ 

The idea would be to run the Hough Transform so that you can get segments of the page which contain rectangles like so:

+---+---+     |   |   |      +---+---+  

Which you would then apply the Hough Transform again and end up with two segments, and you take the left one.

Once that you have the left segment, you would then apply the OCR.

You can try to apply the OCR before hand, but at best, the OCR will recognize both numeric values, both written and both typed, which from what I get, is not what you are after.

Also, the extra lines which depict the rectangles might throw the OCR off track, and make it yield bad results.

like image 198
npinti Avatar answered Sep 19 '22 07:09

npinti