当我使用下面的代码时,将Error设置为“WindowsError:[错误2]系统无法找到指定的文件”。请帮我从图片中获取文字。
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(最近一次调用 最后)in() 2来自PIL import Image 3 ----> 4 print image_to_string(Image.open(r'D:\ name.jpg'),lang ='eng')
C:\ ProgramData \ Anaconda2 \ lib中\站点包\ pytesseract \ pytesseract.pyc in image_to_string(image,lang,boxes,config) 120 lang = lang, 121盒=盒子, - > 122 config = config) 123如果状态: 124 errors = get_errors(error_string)
C:\ ProgramData \ Anaconda2 \ lib中\站点包\ pytesseract \ pytesseract.pyc 在run_tesseract中(input_filename,output_filename_base,lang,boxes, 配置) 44命令+ = shlex.split(config) 45 ---> 46 proc = subprocess.Popen(command,stderr = subprocess.PIPE) 47 status = proc.wait() 48 error_string = proc.stderr.read()
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提升的情况下保留原始异常。
_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:[错误2]系统找不到指定的文件
答案 0 :(得分:2)
从tesseract-ocr安装google tesseract-ocr。代码可能会错过依赖项。
答案 1 :(得分:1)
安装完所有软件包和Tesseract-OCR应用程序后,您应该重新启动电脑。我尝试了你的代码,并得到了相同的问题,但重新启动我的电脑后,它对我有用。请试试。
答案 2 :(得分:0)
您不需要将路径作为原始字符串。 没有原始字符串:
print image_to_string(Image.open('D:\\name.jpg'),lang='eng')
使用原始字符串:
print image_to_string(Image.open(r'D:\name.jpg'),lang='eng')