I tried to read text inside the image using pytesseract and openCV in pycharm editor(windows). It display image but when read the text it show error. Here is my code.
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'
image = cv2.imread('test2.png')
image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
height,width,_ =image.shape
print(height,width)
print(pytesseract.image_to_string(image)) # ****
cv2.imshow('Output', image)
cv2.waitKey(0)
According to this code when I type and run
print (pytesseract.image_to_string(image))
It showed error like follow.
Traceback (most recent call last):
File "D:\Last Update\Uni of Mora\L4S1\FYP\new python project\HTMLCodeGenerator1\test detection.py", line 10, in <module>
print(pytesseract.image_to_string(image))
File "D:\Last Update\Uni of Mora\L4S1\FYP\new python project\HTMLCodeGenerator1\venv\lib\site-packages\pytesseract\pytesseract.py", line 409, in image_to_string
return {
File "D:\Last Update\Uni of Mora\L4S1\FYP\new python project\HTMLCodeGenerator1\venv\lib\site-packages\pytesseract\pytesseract.py", line 412, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "D:\Last Update\Uni of Mora\L4S1\FYP\new python project\HTMLCodeGenerator1\venv\lib\site-packages\pytesseract\pytesseract.py", line 287, in run_and_get_output
run_tesseract(**kwargs)
File "D:\Last Update\Uni of Mora\L4S1\FYP\new python project\HTMLCodeGenerator1\venv\lib\site-packages\pytesseract\pytesseract.py", line 263, in run_tesseract
raise TesseractError(proc.returncode, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (1, 'Error opening data file C:\\Program Files (x86)\\Tesseract-OCR/eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'eng\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')
I tried various ways. But it doesn't work. I changed the environment variable, download test data again but it doesn't work. How I solve this.