display_ocr icon indicating copy to clipboard operation
display_ocr copied to clipboard

Update to python 3?

Open PiOliver opened this issue 8 years ago • 7 comments

Hey, Is possible for this to be updated to work in python 3? I've had a play with the getting it to work but it seems that the wrapper for tesseracts API is broken.

Thanks.

PiOliver avatar Mar 05 '16 11:03 PiOliver

Would be nice. Some time ago I did some tests but didn't had time to go longer and get something that works. Had some problems with newer versions of OpenCV too. I Will take a look when I have some time.

arturaugusto avatar Mar 08 '16 19:03 arturaugusto

Hi, here's my thoughts on the matter.

Pyocr provides, image_to_string, a method for extracting text from an image. In my case, I had to add a couple of lines to the trainer script (tesseract-trainer.py) in order to get access to the trained model. command7 = 'cp -f '+fontname+'.traineddata /usr/local/share/tessdata/' os.system(command7)

After that my implementatiion is something like the following: from pyocr import pyocr from pyocr import builders from PIL import Image import numpy as np ... tool = pyocr.get_available_tools()[0] ###help(tool.image_to_string) ###image_to_string(image, lang=None, builder=None) ... ### tool.get_available_languages() ### ['eng', 'letsgodigital'] lang = 'letsgodigital' # Hardcoding language because I'm being lazy ... ### roi: subsection of the original image. txt = tool.image_to_string(Image.fromarray(roi), lang=lang, builder=builders.TextBuilder())

My system: Ubuntu 14.04 Python 3.4.3

$ pip3.4 freeze | grep -E "ocr|tess" pyocr==0.4.0 pytesseract==0.1.6 tess==0.2 tesseract==0.1.3 tesseract-ocr==0.0.1

Edit: Added PIL and numpy references.

regards Morten S

sphinxligustri avatar Apr 04 '16 18:04 sphinxligustri

@sphinxligustri, good to know there is a simple solution. Could you share the entire code?

arturaugusto avatar Apr 04 '16 21:04 arturaugusto

Here you go, code.py.txt

It's the bare minimum to get some results from my multimeter.

Some notes: I found the resize option handy for large images, but didn't attach it to a slider.

The image path is hard coded in at the moment. p_img = "./images/myImg.jpg"

btw: good job with the training set :+1:

sphinxligustri avatar Apr 05 '16 17:04 sphinxligustri

Thank you @sphinxligustri, I will test it and put on the repository as an alternative python3 compatible script, so others can get benefit of it.

arturaugusto avatar Apr 06 '16 20:04 arturaugusto

hey, Great Job there !! i really like what you are doing guys. :+1: am using python3.4.3 under ubuntu too and the new script of display is still not working: the rectancle doesn't show up.
any ideas?? thanks !! @sphinxligustri @arturaugusto

byrann avatar Aug 29 '16 13:08 byrann

Late to the party, but managed to get it to work on raspberry pi (not zero, which is arm6 and doesn't support "opencv-python" package). Annotated changes to above code from @sphinx.

code.py.txt Cheers

Redwood38 avatar Jul 25 '19 06:07 Redwood38