I need to use python tesseract to extract text from a photo:
import pytesseract
from PIL import Image
img = Image.open('stest.png')
pytesseract.pytesseract.tesseract_cmd = 'D:\\python\\venv\\Scripts\\pytesseract.exe'
file_name = img.filename
file_name = file_name.split(".")[0]
text = pytesseract.image_to_string(img,lang=None, config='')
print(text)
with open(f'{file_name}.txt', 'w') as text_file:
text_file.write(text)
But the error appears as if it is not related to my code:
Traceback (most recent call last):
File "D:\python\pybotavito\main.py", line 13, in <module>
text = pytesseract.image_to_string(img,lang=None, config='')
File "D:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 413, in image_to_string
return {
File "D:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 416, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "D:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 284, in run_and_get_output
run_tesseract(**kwargs)
File "D:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 260, in run_tesseract
raise TesseractError(proc.returncode, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (2, 'Usage: pytesseract [-l lang] input_file')