我写了一个 python/cv2 图像到文本转换器。启动程序C:\Users\mikez\Pictures\examples.png
时,我在要求图像时输入。
此后它显示以下错误:
Traceback:“WindowsError:[错误2]系统找不到指定的文件”。
我不知道我的代码有什么问题:
from PIL import Image
import pytesseract
import os
import cv2
ppc = True
im = raw_input("Enter Image: ")
image = cv2.imread(im)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
while ppc == True:
prepro = raw_input("Enter preprocess: ").lower()
if prepro == "thresh" or prepro == "t":
gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
ppc = False
elif prepro == "blur" or prepro == "b":
gray = cv2.medianBlur(gray, 3)
ppc = False
elif prepro == "no" or "n":
ppc = False
else:
print "Not and option."
ppc = True
filename = "{}.png".format(os.getpid())
cv2.imwrite(filename, gray)
text = pytesseract.image_to_string(Image.open(filename))
os.remove(filename)
print(text)
cv2.imshow("Image", image)
cv2.imshow("Output", gray)
cv2.waitKey(0)