我的代码中出现此错误,如何删除它
我的代码遇到属性错误 “numpy.ndarray”对象没有属性“open” 这是我的代码
import cv2
from PIL import Image
from pytesseract import pytesseract
camera=cv2.VideoCapture(0)
while True:
_,Image=camera.read()
cv2.imshow('Text detection',Image)
if cv2.waitKey(1)& 0xFF==ord('s'):
cv2.imwrite('test1.jpg',Image)
break
camera.release()
cv2.destroyAllWindows()
def tesseract():
path_to_tesseract = "C:\Program Files\Tesseract-OCR\tesseract.exe"
Imagepath='test1.jpg'
pytesseract.tesseract_cmd=path_to_tesseract
text = pytesseract.image_to_string(Image.open(Imagepath))
print(text[:-1])
tesseract()
图片后面必须加逗号:
文本= pytesseract.image_to_string(图像,打开(图像路径))
您正在使用
中的变量覆盖导入的
Image
模块符号
_,Image=camera.read()
不要这样做。将其命名为
image
或其他名称;那么image.open
应该没问题。