gitanat / simple-ocr-opencv

A simple python OCR engine using opencv
GNU Affero General Public License v3.0
525 stars 175 forks source link

Doesn't work on 64bit python #1

Closed hryamzik closed 11 years ago

hryamzik commented 11 years ago

/simple-ocr-opencv/clustering.py:45: RuntimeWarning: invalid value encountered in divide return min(tmp) / max_intra_distance Traceback (most recent call last): File "example.py", line 15, in test_classes, test_segments= ocr.ocr( test_image, show_steps=True ) File "/simple-ocr-opencv/ocr.py", line 40, in ocr segments= self.segmenter.process( image_file.image ) File "/simple-ocr-opencv/processor.py", line 87, in process output= self._process(arguments) File "/simple-ocr-opencv/processor.py", line 131, in _process arguments= p.process( arguments ) File "/simple-ocr-opencv/processor.py", line 87, in process output= self._process(arguments) File "/simple-ocr-opencv/segmentation_aux.py", line 91, in _process raise Exception("different number of lines") Exception: different number of lines

gitanat commented 11 years ago

That's curious. I assume this is on the latest published commit (c5a985)? I get the RuntimeWarning on example.py there too, although the example works; I've been doing something some changes that probably belong on a unstable branch Can you try example.py on commit bce590 and see if that works?

hryamzik commented 11 years ago

Thanks, I'll give this commit a try and will let you know. FYI, here's a possible explanation: http://stackoverflow.com/questions/2752913/why-does-python-array-module-process-strings-and-lists-differently

pedropatinho commented 11 years ago

I get the same issue...

$ python example.py Traceback (most recent call last): File "example.py", line 12, in ocr.train( ImageFile('digits1') ) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/files.py", line 55, in init self.ground.read() File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/files.py", line 35, in read self.classes, self.segments= read_boxfile( self.path ) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/tesseract_utils.py", line 18, in read_boxfile return classes_to_numpy(classes), segments_to_numpy(segments) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/classification.py", line 17, in classes_to_numpy int_classes= array.array( "L", "".join(classes).encode('utf-32')[4:]) ValueError: string length not a multiple of item size

and after changing the "L" for "I" in classification.py line 17:

$ python example.py /usr/lib/python2.7/dist-packages/numpy/lib/function_base.py:489: RuntimeWarning: invalid value encountered in divide avg = a.mean(axis) Traceback (most recent call last): File "example.py", line 15, in test_classes, test_segments= ocr.ocr( test_image, show_steps=True ) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/ocr.py", line 40, in ocr segments= self.segmenter.process( image_file.image ) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/processor.py", line 87, in process output= self._process(arguments) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/processor.py", line 131, in _process arguments= p.process( arguments ) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/processor.py", line 87, in process output= self._process(arguments) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/segmentation_aux.py", line 91, in _process raise Exception("different number of lines") Exception: different number of lines

P.S: this is from the most current master branch

gitanat commented 11 years ago

@pedropatinho As I mentioned, the current master is unusable (my bad) Did you try commit bce590 ? If you get the same result there I'll look into it

pedropatinho commented 11 years ago

Trying it now. Seems to work, but had to change the "L" to "I" in classification.py. Otherwise, would get the first error I reported above.

timprepscius commented 11 years ago

If anyone is reading this, pedropatinho's second letter is not a lowercase "L", it is an upper case "i".. (Github's fonts)

hryamzik commented 11 years ago

Not only github's, stackoverflow's as well. Just copy and paste! ;-)

gitanat commented 11 years ago

If someone having this problem can attach the output of this program I'd be grateful.

import struct
import array
print struct.calcsize("L")
print struct.calcsize("I")
print array.array("L").itemsize
print array.array("I").itemsize
pedropatinho commented 11 years ago

Here it goes:

$ python Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import struct import array print struct.calcsize("L") 8 print struct.calcsize("I") 4 print array.array("L").itemsize 8 print array.array("I").itemsize 4

hryamzik commented 11 years ago

8 4 8 4

gitanat commented 11 years ago

Ok, I've pushed a bugfix branch. Let me know if it runs smoothly, then I'll rebase the master branch to point there.

pedropatinho commented 11 years ago

Well, it works with the example.py, but I'm stucked into getting it to work with my own .png files...

This is more like a question than a bug report, but could you give some details on how to work with my own images? I don't know much about image processing, I'm just trying to do some ocr... When I put an image (some crop of the digits1 or digits2), I get this error:

Traceback (most recent call last): File "example2.py", line 15, in test_classes, test_segments= ocr.ocr( test_image, show_steps=True ) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/ocr.py", line 40, in ocr segments= self.segmenter.process( image_file.image ) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/processor.py", line 87, in process output= self._process(arguments) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/processor.py", line 131, in _process arguments= p.process( arguments ) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/processor.py", line 87, in process output= self._process(arguments) File "/home/pedro/Development/workspace/pokbot/ocr_tests/simple-ocr-opencv/segmentation_aux.py", line 67, in _process if len(tops)!=len(bottoms): Exception: different number of lines

Also, how do I generate my own .box file? I've been browsing the source, but couldn't find it.

Thanks for your efforts, Pedro.

gitanat commented 11 years ago

@pedropatinho

I don't know much about image processing, I'm just trying to do some ocr...

This is intended as an educational project. It's purposefully simple, still very immature and will always have below-average performance as a OCR engine. If you just want to do OCR, you'll probably want to look into Tesseract, or a commercial solution if you need a GUI.

Exception: different number of lines

This currently happens when the engine has trouble guessing the text lines location. I've recently changed the algorithm for this, so you may want to check if the previous one works better for you (check commit c886ac).

Also, how do I generate my own .box file? I've been browsing the source, but couldn't find it.

check issue #2 It's also worth noticing that the box files are in Tesseract's format