img = printscreen_pil
img = img.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(img)
img = enhancer.enhance(2)
img = img.convert('1')
img.save('temp.jpg')
text = pytesseract.image_to_string(Image.open('temp.jpg'))
我想读取图像以便将其转换为文本但我得到的错误系统找不到指定的文件。我认为它与python的工作目录有关。对不起,如果这是一个愚蠢的问题,但我希望你能帮助我。
这是完整的错误mssg。
Traceback (most recent call last):
File "C:\Users\pncor\Documents\pyprograms\bot.py", line 23, in <module>
text = pytesseract.image_to_string(Image.open('temp.jpg'))
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
答案 0 :(得分:3)
您的系统上似乎未安装tesseract
软件包,或者您的路径中找不到该软件包。 tesseract
将pytesseract.image_to_string
二进制文件作为子进程运行,以执行OCR。
使用操作系统上的软件包管理器进行安装,或参考installation documentation。您使用的是Windows,请检查this。
此外,我不认为有必要先将增强型图像写入文件,只需将其直接传递给text = pytesseract.image_to_string(img)
:
$search = array("-", "- ", " -", " - ");
$replace = array("", "", "", "");
$result = str_replace($search, $replace, $text);