1.安装Pillow
pip install Pillow
2.安装tesseract-ocr
github地址: https://github.com/tesseract-ocr/tesseract
或本地下载地址:https://www.jb51.net/softs/538925.html
windows:
The latest installer can be downloaded here: tesseract-ocr-setup-3.05.01.exe and tesseract-ocr-setup-4.00.00dev.exe (experimental).
ubuntu:
sudo apt-get install tesseract-ocr traineddata文件路径: /usr/share/tesseract-ocr/tessdata/
3.安装pytesseract
pip install pytesseract
如不能使用pip直接安装可取搜索模块文件直接安装
遇到问题及解决:
1.FileNotFoundError: [WinError 2] 系统找不到指定的文件
解决办法:
方法1[推荐]: 将tesseract.exe添加到环境变量PATH中,
例如: D:\Tesseract-OCR,默认路径为C:\Program Files (x86)\Tesseract-OCR
注意: 为了使环境变量生效,需要关闭cmd窗口或是关闭pycharm等ide重新启动
方法2: 修改pytesseract.py文件,指定tesseract.exe安装路径
# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe‘
方法3: 在实际运行代码中指定
pytesseract.pytesseract.tesseract_cmd = 'D:\\Tesseract-OCR\\tesseract.exe'
2.pytesseract.pytesseract.TesseractError: (1, 'Error opening data file \\Tesseract-OCR\\tessdata/eng.traineddata')
解决方法:
方法1[推荐]:
将tessdata目录的上级目录所在路径(默认为tesseract-ocr安装目录)添加至TESSDATA_PREFIX环境变量中
例如: C:\Program Files (x86)\Tesseract-OCR
Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory.
方法2: 在.py文件配置中指定tessdata-dir
tessdata_dir_config = '--tessdata-dir "D:\\Tesseract-OCR\\tessdata"' # tessdata_dir_config = '--tessdata-dir "'C:\\Program Files (x86)\\Tesseract-OCR\\tessdata"' pytesseract.image_to_string(image, config=tessdata_dir_config)
trainedata下载地址: the latest from github.com
示例:
# -*-coding:utf-8-*- from PIL import Image import sys import os import pytesseract from selenium import webdriver sys.path.append('C:\Python27\Lib\site-packages\pytesser') import pytesser url='http://192.168.24.189/system/code"code.jpg" driver.find_element_by_id("codeImg").click() driver.save_screenshot(name) #截取当前网页,该网页有我们需要的验证码 aa=Image.open(name) #打开截图 frame4=aa.crop(rangle) #使用Image的crop函数,从截图中再次截取我们需要的区域 frame4.save(name) im = Image.open(name) #转化到灰度图 imgry = im.convert('L') #保存图像 imgry.save('g'+name) #二值化,采用阈值分割法,threshold为分割点 threshold = 140 table = [] for j in range(256): if j < threshold: table.append(0) else: table.append(1) out = imgry.point(table, '1') out.save('b'+name) #识别 text = pytesseract.image_to_string(out) #识别对吗 text = text.strip() text = text.upper(); print (text) text = pytesseract.image_to_string(Image.open('code.png'), lang="eng") print(text)
以上就是python3使用Pillow、tesseract-ocr与pytesseract模块的图片识别的方法的详细内容,更多关于python3 图片识别的资料请关注其它相关文章!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】