Speak in code.
import pytesseract
from PIL import Image
def get_image_string(image_path):
image = Image.open(image_path)
image_str = pytesseract.image_to_string(image, lang='eng')
print(image_str)
return image_str
pytesseract可以简单理解为一个图片文本识别库,详细介绍和安装步骤请看官网:https://pypi.org/project/pytesseract/
以上代码不能直接运行,还需要安装相关软件及配置环境变量,参考链接:tesseract-ocr的安装及使用
经测试识别准确率还可以,可用于无噪点和干扰线的验证码识别。
常见问题:
1. UserWarning: Couldn't allocate palette entry for transparency
图片为RGBA格式,需要转化为RGB格式
image = image.convert('RGB')