第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我可以讓 pytesseract 命令在拋出錯誤的 pycharm 中正常工作嗎

我可以讓 pytesseract 命令在拋出錯誤的 pycharm 中正常工作嗎

暮色呼如 2021-09-14 20:56:31
我正在定義一個功能,它將圖像轉(zhuǎn)換為灰度(位黑白色),然后將其傳遞給:text = pytesseract.image_to_string(Image.open(gray_scale_image))然后我打印我收到的文本,但它拋出錯誤:Traceback (most recent call last):  File "C:\Users\HP\PycharmProjects\nayaproject\venv\lib\site-packages\PIL\Image.py", line 2613, in openfp.seek(0)AttributeError: 'numpy.ndarray' object has no attribute 'seek'During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "C:/Users/HP/PycharmProjects/nayaproject/new.py", line 17, in <module>text = pytesseract.image_to_string(Image.open(g))  File "C:\Users\HP\PycharmProjects\nayaproject\venv\lib\site-packages\PIL\Image.py", line 2615, in openfp = io.BytesIO(fp.read())AttributeError: 'numpy.ndarray' object has no attribute 'read'而不是 Image.open(grayscale),當(dāng)我使用 Image.fromarray(grayscale) 我得到這些錯誤:Traceback (most recent call last):  File "C:\Users\HP\PycharmProjects\nayaproject\venv\lib\site-packages\pytesseract\pytesseract.py", line 170, in run_tesseractproc = subprocess.Popen(cmd_args, **subprocess_args())  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 709, in __init__restore_signals, start_new_session)  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 997, in _execute_childstartupinfo)FileNotFoundError: [WinError 2] The system cannot find the file specifiedDuring handling of the above exception, another exception occurred:我正在研究 PyCharm,并且我已經(jīng)為這個項(xiàng)目安裝了 Pillow、numpy、opencv-python、pip 和 pytesseract。
查看完整描述

1 回答

?
慕俠2389804

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'


查看完整回答
反對 回復(fù) 2021-09-14
  • 1 回答
  • 0 關(guān)注
  • 326 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號