一、問題描述
執行以下代碼報錯
#!/usr/local/bin/python3.7
from PIL import Image
import pytesseract
# 打開圖片
img = Image.open('Reptile/code.png')
# 識別圖片
result = pytesseract.image_to_string(img)
print(result)
二、出現問題原因
圖片模式有問題。
三、解決方案
將圖片模式改為RGB,即增加如下代碼:
img = img.convert('RGB')
