I use the
import cv2,pyautogui,numpy as np
img=np.array(pyautogui.screenshot())
pytesseract.image_to_string(img, lang='eng')
command to get the python wrapper for tesseract to get text from an image for me, which goes through the cli interface basically to save the image to a file and then convert it, which is understandably slow (0.2 seconds on a PC, 3 seconds on a raspberry pi per image).
How do I call the native tesseract library (preferably in python) to directly process an OpenCV/PIL image without going through the CLI?
I have looked into the code here: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/tesseract-ocr/xvTFjYCDRQU/rCEwjZL3BQAJ as sugguested by Pytesseract is too slow. How can I make it process images faster? ,and I can't get any output, even with improvements to get the code from start to finish :
add locale:
import locale locale.setlocale(locale.LC_ALL, 'C')
change all tess.set_variable("tessedit_pageseg_mode", str(frame_piece.psm)) input values to byte:
tess.set_variable(b"tessedit_pageseg_mode", str.encode(str(frame_piece.psm)))
Anyone have any ideas? Would like something that works on windows as well as linux, but I can probably work with anything that works.
P.S. I have tried image>grayscale>threshold>binarization before handing the image to pytesseract and that does give a decent speed boost over using color images, but even then with the IO write involved, it is slow.