今天要做的是验证码识别中最简单的一种办法,采用pytesseract解决,它属于Python当中比较简单的OCR识别库
1.使用pytesseract之前,你需要通过pip 安装一下对应的模块 ,需要两个
pytesseract库还有图像处理的pillow库了
pip install pytesseract
pip install pillow
2.github官网下载pytesseract安装包安装到电脑中,https://github.com/tesseract-ocr/tesseract/wiki
中文包的下载地址 > https://github.com/tesseract-ocr/tessdata
打开第一个链接之后
3. 安装成功之后需要在编译器中配置pytesseract的exe执行程序路径
我的是---->G:\Anconda\Lib\site-packages\pytesseract
接下来配置环境变量
接下来就可以执行一段程序了
import pytesseract
from PIL import Image
def main():
image = Image.open("1.jpg")
text = pytesseract.image_to_string(image,lang="chi_sim")
print(text)
if __name__ == '__main__':
main()
到此就实现了最简单的识别,本篇文章主要参考了以下两篇文章
Python爬虫入门教程 55-100 python爬虫高级技术之验证码篇
tesseract 安装及使用
最后呢有什么问题欢迎大家在评论区留言~