一、问题描述
执行以下代码报错
#!/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')