1 回答

TA贡献1719条经验 获得超6个赞
因为我猜gray_scale_image是从 OpenCV 输出的,因此是 numpy 数组,如错误所示
AttributeError: 'numpy.ndarray' object has no attribute 'read'
您需要将数组转换为 PIL 对象。根据我自己的经验,我建议您将 numpy 数组自动转换为 np.uint8,因为 PIL 使用 8 位,并且您通常不了解 OpenCV 算法的内容。
text = pytesseract.image_to_string(Image.fromarray(gray_scale_image.astype(np.uint8)))
如果上述方法不起作用,则您绝对不会传递任何形式的 Image 数组。尝试输入这些以找到争论的特征:
print(type(gray_scale_image))
print(gray_scale_image.shape)
在这将解决您的第一个问题之后,将会出现您尚不知道的新问题。您需要将路径添加到您的 pytesseract
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path
解决方案是在开头添加您的路径
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
TESSDATA_PREFIX = 'C:/Program Files (x86)/Tesseract-OCR'
添加回答
举报