【发布时间】:2017-11-18 04:51:40
【问题描述】:
我正在尝试使用 openCV 和 python 来构建一个基本的脚本来从图像中读取文本。
现在我被这个错误提示找不到文件,问题是我无法理解这个回溯。哪个文件不存在?任何图书馆或其他一些问题。 它正在编写 thresh.png 和 removednoise.png。
我正在使用 python 3.6,如果有任何兼容性问题,请告诉我。 如果需要更多信息,请告诉我。
通过指向一个方向来帮助我。提前致谢
这是我的代码。
import cv2
import numpy as np
import pytesseract
from PIL import Image
#src_path ="D:/python'/practice"
def get_string(img_path):
img = cv2.imread(img_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((1, 1), np.uint8)
img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)
cv2.imwrite("removed_noise.png", img)
img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
cv2.imwrite("thres.png", img)
result = pytesseract.image_to_string(Image.open("thres.png"))
return result
print ('------------TEXT------------')
print (get_string("imag1.png"))
错误信息:
D:\python'\practice>python OCR_text.py
------------TEXT------------
Traceback (most recent call last):
File "OCR_text.py", line 25, in <module>
print (get_string("imag1.png"))
File "OCR_text.py", line 18, in get_string
result = pytesseract.image_to_string(Image.open("thres.png"))
File "D:\Python\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)
File "D:\Python\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "D:\Python\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "D:\Python\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
【问题讨论】:
标签: python opencv python-imaging-library ocr