pytesseract.image_to_字符串(im)无法访问输入fi

2024-10-03 11:20:54 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试使用pytesseract读取图像中的文本。使用以下两个命令。图像.打开确实正确返回图像,但下一个命令失败,并出现“找不到文件”的windows错误。在

首先,我不明白为什么它要从磁盘中读取图像,因为它已经被前面的语句读取,而图像im已经在内存中了。 然后我把目录包括在pytesseract.exe文件是,在环境变量的路径上,有人建议。同样的问题依然存在。在

我在Windows10上使用Python3.5的anaconda发行版。从Jupyter笔记本上运行代码,而不是python命令行。在

使用pip安装了pytesseract,并在jupyter笔记本中执行了相应的import语句,没有任何错误。在

感谢您对解决此问题的任何帮助。在

im = Image.open('test_image1.png')  
text = pytesseract.image_to_string(im)

FileNotFoundError Traceback (most recent call last) in () 1 im = Image.open('test_image1.png') ----> 2 text = pytesseract.image_to_string(im)

C:\Anaconda3\envs\keras35\lib\site-packages\pytesseract\pytesseract.py in image_to_string(image, lang, config, nice, boxes, output_type) 191 return run_and_get_output(image, 'txt', lang, config, nice, True) 192 --> 193 return run_and_get_output(image, 'txt', lang, config, nice) 194 195

C:\Anaconda3\envs\keras35\lib\site-packages\pytesseract\pytesseract.py in run_and_get_output(image, extension, lang, config, nice, return_bytes) 138 } 139 --> 140 run_tesseract(**kwargs) 141 filename = kwargs['output_filename_base'] + os.extsep + extension 142 with open(filename, 'rb') as output_file:

C:\Anaconda3\envs\keras35\lib\site-packages\pytesseract\pytesseract.py in run_tesseract(input_filename, output_filename_base, extension, lang, config, nice) 109 command.append(extension) 110 --> 111 proc = subprocess.Popen(command, stderr=subprocess.PIPE) 112 status_code, error_string = proc.wait(), proc.stderr.read() 113 proc.stderr.close()

C:\Anaconda3\envs\keras35\lib\subprocess.py in init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds) 674 c2pread, c2pwrite, 675 errread, errwrite, --> 676 restore_signals, start_new_session) 677 except: 678 # Cleanup if the child failed starting.

C:\Anaconda3\envs\keras35\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session) 955 env, 956 cwd, --> 957 startupinfo) 958 finally: 959 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified


Tags: runinpy图像imageconfiglangoutput