简体   繁体   English

无法使用pytesseract从图像中获取文本

[英]unable to get text from image using pytesseract

While I'm using below code , getting Error as "WindowsError:[Error 2] The system cannot find the file specified". 当我使用下面的代码时,将Error设置为“WindowsError:[错误2]系统无法找到指定的文件”。 Please help me to get text from image. 请帮我从图像中获取文字。

from pytesseract import image_to_string
from PIL import Image

print image_to_string(Image.open(r'D:\\name.jpg'),lang='eng')

ERROR: 错误:

WindowsError Traceback (most recent call last) in () 2 from PIL import Image 3 ----> 4 print image_to_string(Image.open(r'D:\\name.jpg'),lang='eng') 从PIL导入的()2中的WindowsError Traceback(最近一次调用最后一次)导入图像3 ----> 4 print image_to_string(Image.open(r'D:\\ name.jpg'),lang ='eng')

C:\\ProgramData\\Anaconda2\\lib\\site-packages\\pytesseract\\pytesseract.pyc in image_to_string(image, lang, boxes, config) 120 lang=lang, 121 boxes=boxes, --> 122 config=config) 123 if status: 124 errors = get_errors(error_string) image_to_string(image,lang,boxes,config)中的C:\\ ProgramData \\ Anaconda2 \\ lib \\ site-packages \\ pytesseract \\ pytesseract.pyc 120 lang = lang,121 boxes = boxes, - > 122 config = config)123 if status :124 errors = get_errors(error_string)

C:\\ProgramData\\Anaconda2\\lib\\site-packages\\pytesseract\\pytesseract.pyc in run_tesseract(input_filename, output_filename_base, lang, boxes, config) 44 command += shlex.split(config) 45 ---> 46 proc = subprocess.Popen(command, stderr=subprocess.PIPE) 47 status = proc.wait() 48 error_string = proc.stderr.read() run_tesseract中的C:\\ ProgramData \\ Anaconda2 \\ lib \\ site-packages \\ pytesseract \\ pytesseract.pyc(input_filename,output_filename_base,lang,boxes,config)44命令+ = shlex.split(config)45 ---> 46 proc = subprocess .Popen(command,stderr = subprocess.PIPE)47 status = proc.wait()48 error_string = proc.stderr.read()

C:\\ProgramData\\Anaconda2\\lib\\subprocess.pyc in init (self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags) 388 p2cread, p2cwrite, 389 c2pread, c2pwrite, --> 390 errread, errwrite) 391 except Exception: 392 # Preserve original exception in case os.close raises. init中的 C:\\ ProgramData \\ Anaconda2 \\ lib \\ subprocess.pyc(self,args,bufsize,executable,stdin,stdout,stderr,preexec_fn,close_fds,shell,cwd,env,universal_newlines,startupinfo,creationflags)388 p2cread,p2cwrite, 389 c2pread,c2pwrite, - > 390 errread,errwrite)391除了例外:392#在os.close提升的情况下保留原始异常。

C:\\ProgramData\\Anaconda2\\lib\\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite) 638 env, 639 cwd, --> 640 startupinfo) 641 except pywintypes.error, e: 642 # Translate pywintypes.error to WindowsError, which is _execute_child中的C:\\ ProgramData \\ Anaconda2 \\ lib \\ subprocess.pyc(self,args,executable,preexec_fn,close_fds,cwd,env,universal_newlines,startupinfo,creationflags,shell,to_close,p2cread,p2cwrite,c2pread,c2pwrite,errread,errwrite )638 env,639 cwd, - > 640 startupinfo)641除了pywintypes.error,e:642#将pywintypes.error转换为WindowsError,这是

WindowsError: [Error 2] The system cannot find the file specified WindowsError:[错误2]系统找不到指定的文件

Install google tesseract-ocr from tesseract-ocr . tesseract-ocr安装google tesseract -ocr The code might miss dependencies. 代码可能会错过依赖项。

After installation of all package and Tesseract-OCR app, you should restart your PC. 安装所有软件包和Tesseract-OCR应用程序后,您应重新启动PC。 I tried your code and get the same problem but after restart my PC it worked for me. 我尝试了你的代码,并得到了相同的问题,但重新启动我的电脑后,它对我有用。 Please try. 请试试。

You dont need to give the path as raw string. 你不需要将路径作为原始字符串。 Without raw string: 没有原始字符串:

print image_to_string(Image.open('D:\\name.jpg'),lang='eng')

With raw string: 使用原始字符串:

print image_to_string(Image.open(r'D:\name.jpg'),lang='eng')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 pytesseract.image_to_string 从图像中读取文本 - Unable to read text from Image using pytesseract.image_to_string 无法在python中使用pytesseract从tif图像中提取文本 - unable to extract text from tif image using pytesseract in python 如何使用pytesseract从图像中提取文本? - How to extract text from image using pytesseract? 使用pytesseract从图像中提取文本 - Extract text from image using pytesseract 无法使用 pytesseract 从 .jpg 图像中提取全文,仅提取了部分文本,存在拼写错误 - Unable to extract full text from .jpg image using pytesseract just partial text is extracted that to have spelling mistakes pyTesseract不从图像输出文本 - pyTesseract not outputing text from image 使用 pytesseract 从图像中提取文本 - Extract text from image with pytesseract 如何使用 pytesseract 从图像中的特定边界框中提取文本? - How to extract text from specific bounding boxes in an image using pytesseract? 使用 openCV 和 Pytesseract 从屏幕(不是图像)读取数字/文本并显示它 - reading the numbers/text from the screen (not image) using openCV and Pytesseract and displaying it 是否可以使用 pytesseract 从图像的特定部分提取文本 - Is it possible to extract text from specific portion of image using pytesseract
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM