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?
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:
You will most likely need to do the following:
Apply the Hough Transform algorithm on the entire page, this should should yield a series of page sections.
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.
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:
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.
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.