You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm working on a Fedora 32 distro with tesseract 5.0.0-alpha-20201224 and pytesseract Version: 0.3.10.
when I call this function image_to_string(image, lang="letsgodigital", config="--oem 4 --psm 100 -c tessedit_char_whitelist=.0123456789")
I received this error:
Traceback (most recent call last):
File "main2.py", line 8, in <module>
str_Res = digital_display_ocr.ocr_image(image)
File "/home/fili/workspace/python/digit_recognition/digital_display_ocr.py", line 107, in ocr_image
return image_to_string(otsu_thresh_image, lang="letsgodigital", config="--oem 4 --psm 100 -c tessedit_char_whitelist=.0123456789")
File "/home/fili/.local/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 423, in image_to_string
return {
File "/home/fili/.local/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 426, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "/home/fili/.local/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 290, in run_and_get_output
with open(filename, 'rb') as output_file:
FileNotFoundError: [Errno 2] File o directory non esistente: '/tmp/tess_4p1bawg8.txt'
pytesseract will never actually write to the output file itself, but the underlying Tesseract binary. Do you get any output if you call Tesseract manually with your options? What is the final cmd_args in your case in pytesseract.pytesseract.run_tesseract?
Additionally: It seems like you are using a pre-release version of Tesseract. Are you able to test this with a regular release, as Tesseract 5.2.0 has been released about half a year ago?
I got the same error on the image_to_pdf_or_hocr method and saw at line 290 of pytesseract.py (and as is seen above in quoted error message from filirnd), that the output tmp file is being opened as 'rb', when it seems like it should be 'wb'.
I got the same error on the image_to_pdf_or_hocr method [...]
As mentioned in my previous comment: What command is sent to Tesseract? Which Tesseract version are you using? What happens if you call Tesseract on this file directly? Do you have a reproducer? Nevertheless, this probably is a Tesseract issue, not a pytesseract one.
[...] and saw at line 290 of pytesseract.py (and as is seen above in quoted error message from filirnd), that the output tmp file is being opened as 'rb', when it seems like it should be 'wb'.
rb is completely fine here, as the corresponding file should be created by Tesseract. If it is not being created, this seems to be a Tesseract issue which might be related to your input data (see the first part of my comment).
rb is completely fine here, as the corresponding file should be created by Tesseract. If it is not being created, this seems to be a Tesseract issue which might be related to your input data (see the first part of my comment).
OK, this info helped me dig into it a bit farther, as I certainly hadn't understood the underlying call to tesseract binary, but yes of course I now see that is 'rb' for an input file. So eventually I found instead that I had a missing argument to the pytesseract.image_to_pdf_or_hocr. Whereas I had copied this from the example on the pytesseract doc page at https://pypi.org/project/pytesseract/: hocr = pytesseract.image_to_pdf_or_hocr('test.png', extension='hocr')
what was missing was the additional config argument: hocr = pytesseract.image_to_pdf_or_hocr('test.png', extension='hocr', config='-c tessedit_create_hocr=1)
without this additional argument, the tesseract binary is creating a .txt extension by some kind of default, even though the extension arg is being correctly assigned as 'hocr'.
Have you tried running the same command (with the temporary files replaced by "real" files) with Tesseract directly? Does this generate the correct files?
I have tried, and it does generate the correct files, but the issue was eventually linked to me not including a config = " -c tessedit_create_boxfile=1",
Activity
stefan6419846 commentedon Sep 30, 2022
Could you please try to quote the
tessedit_char_whitelistvalue, id estconfig="--oem 4 --psm 100 -c tessedit_char_whitelist='.0123456789'"?filirnd commentedon Sep 30, 2022
Same error.
It seems like pytesseract can't write the output file.
stefan6419846 commentedon Sep 30, 2022
pytesseract will never actually write to the output file itself, but the underlying Tesseract binary. Do you get any output if you call Tesseract manually with your options? What is the final
cmd_argsin your case inpytesseract.pytesseract.run_tesseract?Additionally: It seems like you are using a pre-release version of Tesseract. Are you able to test this with a regular release, as Tesseract 5.2.0 has been released about half a year ago?
jeb2112 commentedon Dec 23, 2022
I got the same error on the
image_to_pdf_or_hocrmethod and saw at line 290 of pytesseract.py (and as is seen above in quoted error message from filirnd), that the output tmp file is being opened as 'rb', when it seems like it should be 'wb'.stefan6419846 commentedon Dec 24, 2022
As mentioned in my previous comment: What command is sent to Tesseract? Which Tesseract version are you using? What happens if you call Tesseract on this file directly? Do you have a reproducer? Nevertheless, this probably is a Tesseract issue, not a pytesseract one.
rbis completely fine here, as the corresponding file should be created by Tesseract. If it is not being created, this seems to be a Tesseract issue which might be related to your input data (see the first part of my comment).jeb2112 commentedon Dec 27, 2022
OK, this info helped me dig into it a bit farther, as I certainly hadn't understood the underlying call to tesseract binary, but yes of course I now see that is 'rb' for an input file. So eventually I found instead that I had a missing argument to the
pytesseract.image_to_pdf_or_hocr. Whereas I had copied this from the example on the pytesseract doc page at https://pypi.org/project/pytesseract/:hocr = pytesseract.image_to_pdf_or_hocr('test.png', extension='hocr')what was missing was the additional config argument:
hocr = pytesseract.image_to_pdf_or_hocr('test.png', extension='hocr', config='-c tessedit_create_hocr=1)without this additional argument, the tesseract binary is creating a .txt extension by some kind of default, even though the extension arg is being correctly assigned as 'hocr'.
stefan6419846 commentedon Dec 30, 2022
I cannot reproduce this issue on Linux running Tesseract 4.1.0 (shortened output):
Could you please provide some more details about your setup and versions?
DrPlanecraft commentedon Jun 20, 2023
Hi! I got the same issue, my setup versions are as follows:
Python :
Tesseract:
Command Being sent:
In my case I can never see the
tess_<temp code>.boxfile being generatedthis is my error message:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\DRPLAN~1\\AppData\\Local\\Temp\\tess_r3wvoqfl.box'stefan6419846 commentedon Jun 21, 2023
Have you tried running the same command (with the temporary files replaced by "real" files) with Tesseract directly? Does this generate the correct files?
DrPlanecraft commentedon Jun 22, 2023
I have tried, and it does generate the correct files, but the issue was eventually linked to me not including a
config = " -c tessedit_create_boxfile=1",