I'm trying read texts from an image using pytesseract but it throws this error no matter what I try.
Code:
import os
import subprocess
import pytesseract
from PIL import Image
subprocess.call('dir', shell=True)
print(os.path.isfile("test.jpg")) #True
im = Image.open("test.jpg")
text = pytesseract.image_to_string(im)
OUTPUT:
Traceback (most recent call last):
File "F:/Programming/PYTHON/captcha/test/main.py", line 10, in <module>
text = pytesseract.image_to_string(im)
File "F:\Program Files (64bit)\Python\lib\site-packages\pytesseract\pytesseract.py", line 193, in image_to_string
return run_and_get_output(image, 'txt', lang, config, nice)
File "F:\Program Files (64bit)\Python\lib\site-packages\pytesseract\pytesseract.py", line 140, in run_and_get_output
run_tesseract(**kwargs)
File "F:\Program Files (64bit)\Python\lib\site-packages\pytesseract\pytesseract.py", line 111, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "F:\Program Files (64bit)\Python\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "F:\Program Files (64bit)\Python\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Process finished with exit code 1
what's wrong? I know that file is there. I checked it using os.path.isfile and subprocess call
Other things that I tried:
-added full image file path using string literal 'r'
-tried different images and file types
Related
Hello I am trying to make a python script that takes an image file from a computer and turn it into text. At the moment, I have the following code
from tkinter import Tk
from tkinter.filedialog import askopenfilename
import pytesseract
Tk().withdraw()
filename = askopenfilename()
print(filename)
pytesseract.pytesseract.tesseract_cmd = filename
print(pytesseract.image_to_string(filename))
However this gives me the error
Traceback (most recent call last):
File "main.py", line 11, in <module>
print(pytesseract.image_to_string(filename))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 409, in image_to_string
return {
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 412, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 287, in run_and_get_output
run_tesseract(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 258, in run_tesseract
raise e
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 255, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/Users/william/theimage.jpg'
What am I doing wrong?
this: pytesseract.pytesseract.tesseract_cmd = filename is absolutely wrong.
tesseract_cmd should have your tesseract engine executable path.
you need to find where you installed tesseract.
pytesseract.pytesseract.tesseract_cmd = <path_to_tesseract_engine>
# example
# pytesseract.pytesseract.tesseract_cmd = "/some_folder1/some_folder2/...
# /<where_you_installed_tesseract_cmd>/tesseract.<whatever_is_the_extension_for_executables_on_mac>"
you get permission error because you set the tesseract_cmd to link the path to your image and when you actually use pytesseract.image_to_string(<your_image>) ofcourse it raises permission denied because the image is used by the tesseract_cmd process.
after you set your engine.
this is gonna be fine
print(pytesseract.image_to_string(filename))
I'm using pytesseract in Python for pdf. But I'm getting permission error in windows 10.
I have install tesseract-ocr-w64-setup-v5.0.0-alpha.20200328.exe from https://github.com/UB-Mannheim/tesseract/wiki
I have also poppler-20.09.0 files. and I`m using python 3.8.0
import pdf2image
import PyPDF2
import os
try:
from PIL import Image
except ImportError:
import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR'
def pdf_to_img(pdf_file):
print('pdf_file = ', pdf_file)
return pdf2image.convert_from_path(pdf_file, dpi=200, fmt='jpg',
poppler_path=r'F:\lokesh\resume_script\poppler-20.09.0\bin')
def ocr_core(file):
text = pytesseract.image_to_string(file,)
return text
def print_pages(pdf_file):
images = pdf_to_img(pdf_file)
for pg, img in enumerate(images):
print(ocr_core(img))
print_pages("aa.pdf")
when I run this code. it gives this error.
Traceback (most recent call last):
File "test.py", line 84, in <module>
print_pages("aa.pdf")
File "test.py", line 81, in print_pages
print(ocr_core(img))
File "test.py", line 74, in ocr_core
text = pytesseract.image_to_string(file,)
File "F:\python\lib\site-packages\pytesseract\pytesseract.py", line 344, in image_to_string
return {
File "F:\python\lib\site-packages\pytesseract\pytesseract.py", line 347, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "F:\python\lib\site-packages\pytesseract\pytesseract.py", line 258, in run_and_get_output
run_tesseract(**kwargs)
File "F:\python\lib\site-packages\pytesseract\pytesseract.py", line 229, in run_tesseract
raise e
File "F:\python\lib\site-packages\pytesseract\pytesseract.py", line 226, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "F:\python\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "F:\python\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied
how can we solve this error in windows
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR'
needs to be
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
As a part of some automation I am trying to connect to mainframe using python, where I can access the mainframe files and create a
report. Just like using mainframe files as DB for python program.
To login to mainframe - we need to provide host details(xyz.host.com)
followed with region details(h123p) and then with our credentials.
I found that we can do this using python package py3270 and tried doing it but getting the error.
from py3270 import Emulator
# or not (uses s3270)
em = Emulator()
em.connect('xyx.example.com')
em.fill_field(3, 1, 'xxxx',5)
em.send_enter()
em.fill_field(2, 1, 'xxxxxxx', 7)
em.send_enter()
em.fill_field(8, 20, 'xxxxxxxx', 8)
em.send_enter()
# if your host unlocks the keyboard before truly being ready you can use:
em.wait_for_field()
# maybe look for a status message
if not em.string_found(1, 2, 'login succesful'):
abort()
# do something useful
# disconnect from host and kill subprocess
em.terminate()
The error:
File "C:/Users/vganr/PycharmProjects/test/mainframe.py", line 6, in
<module>
em = Emulator()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 273, in __init__
self.app = app or self.create_app(visible, args)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 291, in create_app
return Ws3270App(args)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 140, in __init__
self.spawn_app()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 145, in spawn_app
args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 775,
in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 1178,
in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Exception ignored in: <function Emulator.__del__ at 0x038CB810>
Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 285, in __del__
self.terminate()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 320, in terminate
if not self.is_terminated:
AttributeError: 'Emulator' object has no attribute 'is_terminated'
Based on the error messages you're seeing, I suspect you're having a problem with missing/not found x3270/s3270 libraries.
return Ws3270App(args)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 140, in __init__
self.spawn_app()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 145, in spawn_app
args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 775,
in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 1178,
in _execute_child
startupinfo)
The above suggests that the library is trying to start Ws3270, the windows version of x3270, and is unable to do so.
Make sure the the required libraries are in your path and visible from python.
I want to create an experiment with Psychopy in which I will present randomly video that participant will have to evaluate.
I have created a routine with my MovieStim and my Rating response and a Loop with my conditions file (in which are my video files videoname.wmv).
All my videos are in the same folder as my experiment.
I have specified the MovieStim with a variable refering to my Loop's column ($Stimulus).
But when I run the experiment I have this message.
Running: E:\Thèse ESPRIT\Approach_Aversion\Experience_AA\Approach_Aversion_lastrun.py
pyo version 0.8.0 (uses single precision)
WARNING:root:Warning: could not find imageio's ffmpeg executable:
[Error 5] Accès refus: 'C:\\Program Files (x86)\\PsychoPy2\\lib\\site-packages\\imageio\\resources\\ffmpeg\\ffmpeg.win32.exe'
Traceback (most recent call last):
File "E:\Thèse ESPRIT\Approach_Aversion\Experience_AA\Approach_Aversion_lastrun.py", line 105, in <module>
depth=0.0,
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\contrib\lazy_import.py", line 120, in __call__
return obj(*args, **kwargs)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\visual\movie3.py", line 124, in __init__
self.loadMovie(self.filename)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\visual\movie3.py", line 170, in loadMovie
self._mov = VideoFileClip(filename, audio=(1 - self.noAudio))
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 55, in __init__
reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 32, in __init__
infos = ffmpeg_parse_infos(filename, print_infos, check_duration)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 237, in ffmpeg_parse_infos
proc = sp.Popen(cmd, **popen_params)
File "C:\Program Files (x86)\PsychoPy2\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Program Files (x86)\PsychoPy2\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] Le fichier spécifié est introuvable
It seems to be something wrong with the ffmpeg executable but I don't understand what.
Do you have any idea ?
Thank you very much fo advance !
Have a nice day.
Ivane
I try to use osm-bundler:
ubuntu: ~/osm-bundler$ ./RunBundler.py —photos="/home/ubuntu/photo"
Working directory created: /home/ubuntu/osm-bundler/output/osm-bundler-o1drFG
BundlerMatching executable path: /home/ubuntu/osm-bundler/software/bundler/KeyMatchFull
Sift executable path: /home/ubuntu/osm-bundler/software/sift-lowe/sift
but i get an error:
Processing photo 'IMGP3417.jpg':
Copy of the photo has been scaled down to 1200x900
Traceback (most recent call last):
File "./RunBundler.py", line 10, in <module>
manager.preparePhotos()
File "/home/ubuntu/osm-bundler/osmbundler/__init__.py", line 168, in preparePhotos
self._preparePhoto(photoInfo)
File "/home/ubuntu/osm-bundler/osmbundler/__init__.py", line 278, in _preparePhoto
self.extractFeatures(photo)
File "/home/ubuntu/osm-bundler/osmbundler/__init__.py", line 345, in extractFeatures
self.featureExtractor.extract(photo, self.photoDict[photo])
File "/home/ubuntu/osm-bundler/osmbundler/features/siftlowe.py", line 25, in extract
p = subprocess.call(self.executable, **dict(stdin=photoFile, stdout=siftTextFile))
File "/usr/lib/python2.7/subprocess.py", line 523, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Lines 23,24, & 25 of siftlowe.py:
photoFile = open("%s.jpg.pgm" % photo, "rb")
siftTextFile = open("%s.key" % photo, "w")
subprocess.call(self.executable, **dict(stdin=photoFile, stdout=siftTextFile))
File permissions are set correctly.
It looks like you did only install osm-bundler.zip and not osm-budler-full.zip. The line with the self.executable tries to execute sift, which is expected at /home/ubuntu/osm-bundler/software/sift-lowe/sift. This is most probably not installed (I tried it myself with osm-bundler.zip and this was missing).