python tesseract-ocr 基础验证码识别功能(Windows)
一、环境
windows 7 x64
Python 3 +
二、安装
1、tesseract-ocr安装
http://digi.bib.uni-mannheim.de/tesseract/
2、pytesseract安装
pip install pytesseract
3、Pillow 安装
pip install pillow
三、使用
#! -*- coding:utf-8 -*- import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = 'c://Program Files (x86)//Tesseract-OCR//tesseract.exe' tessdata_dir_config = '--tessdata-dir "c://Program Files (x86)//Tesseract-OCR//tessdata"' def main():
image = Image.open('code.png')
code = pytesseract.image_to_string(image, lang = 'eng', config=tessdata_dir_config)
print (code) if __name__ == '__main__':
main()
四、心得、遇到的坑
1、在 Windows 环境下的支持没有那么好,单单导入 import pytesseract 包,会一直报 Not Find 的错误。
原因:没有找到安装步骤中的 tesseract-ocr 应用程序,需在代码中加入引用:
pytesseract.pytesseract.tesseract_cmd = 'c://Program Files (x86)//Tesseract-OCR//tesseract.exe'
2、image_to_string 需要重载两个参数,大概的理解,
lang = 'eng' 会找到 tessdate_dir_config 下配置路径下的 tessdata 文件夹下的 eng.traineddata 文件,
config= 则是引用路径
可以根据 tessdata 目录下的 *.traineddata 文件进行配置不同的识别库(不知道是否正确,大概的理解是这样)
错误提示:
Traceback (most recent call last):
File "D:\***\VerifyCodeTest\src\main.py", line 17, in <module>
main()
File "D:\***\VerifyCodeTest\src\main.py", line 11, in main
code = pytesseract.image_to_string(image, lang = 'eng', config=tessdata_dir_config)
File "C:\Users\*\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 193, in image_to_string
return run_and_get_output(image, 'txt', lang, config, nice)
File "C:\Users\*\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 140, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\*\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 111, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "C:\Users\*\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\*\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
File "D:\***\VerifyCodeTest\src\main.py", line 17, in <module>
main()
File "D:\***\VerifyCodeTest\src\main.py", line 11, in main
code = pytesseract.image_to_string(image)#, lang = 'eng', config=tessdata_dir_config)
File "C:\Users\*\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 193, in image_to_string
return run_and_get_output(image, 'txt', lang, config, nice)
File "C:\Users\*\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 140, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\*\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 116, in run_tesseract
raise TesseractError(status_code, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (1, 'Error opening data file \\Program Files (x86)\\Tesseract-OCR\\eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'eng\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')
参考自:https://blog.csdn.net/a349458532/article/details/51490291
python tesseract-ocr 基础验证码识别功能(Windows)的更多相关文章
- python之web自动化验证码识别解决方案
验证码识别解决方案 对于web应用程序来讲,处于安全性考虑,在登录的时候,都会设置验证码,验证码的类型种类繁多,有图片中辨别数字字母的,有点击图片中指定的文字的,也有算术计算结果的,再复杂一点就是滑动 ...
- python使用tesseract-ocr完成验证码识别(模型训练和使用部分)
一.Tesseract训练 大体流程为:安装jTessBoxEditor -> 获取样本文件 -> Merge样本文件 –> 生成BOX文件 -> 定义字符配置文件 -> ...
- Python之验证码识别功能
Python之pytesseract 识别验证码 1.验证码来一个 2.适合什么样的验证码呢? 只能识别简单.静态.无重叠.只有数字字母的验证码 3.实际应用:模拟人工登录.页面内容识别.爬虫抓取信息 ...
- 分享一个爬取HUST(哈理工)学生成绩的Python程序(OCR自动识别验证码)
Python版本:3.5.2 日期:2018/1/21 __Author__ = "Lance#" # -*- coding = utf-8 -*- from urllib imp ...
- python使用tesseract-ocr完成验证码识别
全自动区分计算机和人类的公开图灵测试(Completely Automated Public Turing test to tell Computers and Humans Apart) 简称CAP ...
- 使用Python基于OpenCV的验证码识别
Blog:https://blog.csdn.net/qq_40962368/article/details/89312429(Verification_Code_Identification) 步骤 ...
- python使用tesseract-ocr完成验证码识别(安装部分)
一.tesseract-ocr安装 Ubuntu版本: 1.tesseract-ocr安装 sudo apt-get install tesseract-ocr 2.pytesseract安装 sud ...
- Mac python Tesseract 验证码识别
Tesseract 简介 Tesseract(/'tesərækt/) 这个词的意思是"超立方体",指的是几何学里的四维标准方体,又称"正八胞体".不过这里要讲 ...
- python3.7验证码识别MuggleOCR,为什么总是报错
先来看看MuggleOCR简介(白嫖)这是一个为麻瓜设计的本地OCR模块只需要简单几步操作即可拥有两大通用识别模块,让你在工作中畅通无阻. 这套模型是基于 https://github.com/ker ...
随机推荐
- 006-HotSpot JVM收集器
一.概述 1.1.图解 上面有7中收集器,分为两块,上面为新生代收集器,下面是老年代收集器.如果两个收集器之间存在连线,就说明它们可以搭配使用. JVM给出了3类选择:串行收集器.并行收集器.并发收集 ...
- window7+wamp环境配置Oracle数据库连接
最近开发需要使用的oracle数据库!翻看了PHP手册,也在网上找了些帖子!功夫不负有心人,花费了四五个小时的时间,终于找到了Oracle的配置方法.下面就讲解下如何配置Oracle数据库连接吧! 附 ...
- 开启无线WLAN方式
1.以管理员身份运行命令提示符 因为下面的步骤必须在管理员权限下运行,因此我们从开始菜单找到"命令提示符",或直接键入cmd快速搜索,右键单击它,选择"以管理员身份运行& ...
- NIO服务端和客户端通信demo
代码转自 https://www.jianshu.com/p/a9d030fec081 服务端: package nio; import java.io.IOException; import jav ...
- Python3:input()输入函数的用法
Python3:input()输入函数的用法 一.简介 input这个函数,第一个参数是提示语,它默认是空的.在我们使用input的时候,会从标准输入中读取一个string,即字符串(请注意,这里很重 ...
- [pixhawk笔记]4-如何写一个简单的应用程序
本文主要内容来自于:https://dev.px4.io/en/tutorials/tutorial_hello_sky.html,并对文档中的部分问题进行更正. 本文假设已经建立好开发环境并能正确编 ...
- nginx日志分割总结
nginx日志自己不会进行分个,所有日志都会累积的记录在 access.log,error.log 中,当请求量大,一天就能到几百兆,如果不进行分给,对日志的查看和写入性能都有影响. 1. 编写脚本n ...
- UIScrollView监听静止的数种情况
1.直接通过block -(void)testInBlock { //通过block监听 [UIView animateWithDuration:1.0 animations:^{ self.scro ...
- 程序包com.sun.istack.internal不存在
添加一下依赖 <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl --><dependency> ...
- 《Maven实战》第5章 坐标和依赖
5.1 Maven坐标——项目唯一标识 groupId(必须定义):定义Mavan项目隶属的实际项目,如SpringFramework,一个实际项目可包含多个Maven项目 artifactId(必须 ...