1 回答

TA貢獻(xiàn)1719條經(jīng)驗(yàn) 獲得超6個贊
因?yàn)槲也耮ray_scale_image是從 OpenCV 輸出的,因此是 numpy 數(shù)組,如錯誤所示
AttributeError: 'numpy.ndarray' object has no attribute 'read'
您需要將數(shù)組轉(zhuǎn)換為 PIL 對象。根據(jù)我自己的經(jīng)驗(yàn),我建議您將 numpy 數(shù)組自動轉(zhuǎn)換為 np.uint8,因?yàn)?PIL 使用 8 位,并且您通常不了解 OpenCV 算法的內(nèi)容。
text = pytesseract.image_to_string(Image.fromarray(gray_scale_image.astype(np.uint8)))
如果上述方法不起作用,則您絕對不會傳遞任何形式的 Image 數(shù)組。嘗試輸入這些以找到爭論的特征:
print(type(gray_scale_image))
print(gray_scale_image.shape)
在這將解決您的第一個問題之后,將會出現(xiàn)您尚不知道的新問題。您需要將路徑添加到您的 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'
添加回答
舉報(bào)