python图片识别
python 图像处理模块
1. 安装 pytesseract模块是会自动安装Pillow模块。
pillow 为标准图像处理库
手册地址 http://pillow-cn.readthedocs.io/zh_CN/latest/index.html
pytesseract 模块用于文字识别
pip3 install pytesseract
2. 安装 tesseract-ocr 这个用于文字识别
pytesseract 需要调用它
https://github.com/tesseract-ocr/tesseract/wiki
参考:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014320027235877860c87af5544f25a8deeb55141d60c5000
https://blog.csdn.net/dcba2014/article/details/78969658
https://blog.csdn.net/iodjSVf8U1J7KYc/article/details/79308086
3. 常见错误:
1. 注意使用python版本和安装模块的版本
2. ImageOps 需要使用 from PIL import ImageOps
不能直接使用PIL.ImageOps
3. 先引入
from lxml import html
from pyquery import PyQuery as pq
在引入
# 图片识别
from PIL import ImageOps
from PIL import Image
import pytesseract
发现报错误OSError: codec configuration error when reading image file
问题感觉比较奇葩
解决: 将图片库的引入在 pqquery 之前
例子1
转自:https://www.cnblogs.com/MrRead/p/7656800.html 有简单修改 让代码能在python3上运行
1、验证码的识别是有针对性的,不同的系统、应用的验证码区别有大有小,只要处理好图片,利用好pytesseract,一般的验证码都可以识别
2、我在识别验证码的路上走了很多弯路,重点应该放在怎么把图片处理成这个样子,方便pytesseract的识别,以提高成功率

3、原图为:

# 图片识别
from PIL import ImageOps
from PIL import Image
import pytesseract
def initTable(threshold=140):
table = []
for i in range(256):
if i < threshold:
table.append(0)
else:
table.append(1)
return table
im = Image.open('8fnp.png')
#图片的处理过程
im = im.convert('L')
binaryImage = im.point(initTable(), '1')
im1 = binaryImage.convert('L')
im2 = ImageOps.invert(im1)
im3 = im2.convert('1')
im4 = im3.convert('L')
#将图片中字符裁剪保留
box = (30,10,90,28)
region = im4.crop(box)
#将图片字符放大
out = region.resize((120,38))
asd = pytesseract.image_to_string(out)
print(asd)
print (out.show())

上面代码可以识别出图片验证码
python图片识别的更多相关文章
- Python图片识别找坐标(appium通过识别图片点击坐标)
***如果只想了解图片相似度识别,直接看第一步即可 ***如果想了解appium根据图片识别点击坐标,需要看第一.二.三步 背景|在做UI测试时,发现iOS自定义的UI控件,appium识别不到. ...
- Python图片识别——人工智能篇
一.安装pytesseract和PIL PIL全称:Python Imaging Library,python图像处理库,这个库支持多种文件格式,并提供了强大的图像处理和图形处理能力. 由于PIL仅 ...
- 基于python图片识别工具(图片识别,车牌,PDF,验证码)
先上图 不多说. 对于一般的用户来说识别率还是能达到百分之90以上. 已经打包成exe文件.windows用户可以直接使用.要软件的加我QQ python代码: # -*- coding: UTF- ...
- python 图片识别灰度
# -*- coding: cp936 -*- from skimage import io,transform,color import numpy as np def convert_gray(f ...
- Python 图片识别
Tesseract是开源的OCR引擎. 需要安装tesserocr.opencv-python.tesseract-ocr pip install tesserocr pip install open ...
- Python 3 实现色情图片识别
Python 3 实现色情图片识别 项目简介 项目内容 本实验将使用 Python3 去识别图片是否为色情图片,我们会使用到 PIL 这个图片处理库,会编写算法来划分图像的皮肤区域. 项目知识点 Py ...
- Python人工智能之图片识别,Python3一行代码实现图片文字识别
1.Python人工智能之图片识别,Python3一行代码实现图片文字识别 2.tesseract-ocr安装包和中文语言包 注意:
- 用python实现数字图片识别神经网络--启动网络的自我训练流程,展示网络数字图片识别效果
上一节,我们完成了网络训练代码的实现,还有一些问题需要做进一步的确认.网络的最终目标是,输入一张手写数字图片后,网络输出该图片对应的数字.由于网络需要从0到9一共十个数字中挑选出一个,于是我们的网络最 ...
- 【328】Python 控制鼠标/键盘+图片识别 综合应用
本文是基于 [267]实现跨网络传数据 的基础上的,由于在弹出 putty 之后,需要手动输入命令(pass.sh.get.sh)来实现数据的传递,另外就是处理完之后需要手动关闭 putty,本文解决 ...
随机推荐
- python 获取进程数据
from multiprocessing import Process, Manager def func(dt, lt): ): key = 'arg' + str(i) dt[key] = i * ...
- git批量删除文件和批量提交
1. 单个删除文件: ① 通常直接在文件管理器中把没用的文件删了,或者用rm命令删了:(可选操作,可直接执行②删除) $ rm test.txt ② 确实要从版本库中删除该文件,那就用命令git rm ...
- (转)Nandflash读写
------------------------------------------------------------------------------------------文章1------- ...
- vs2015多行注释与取消多行注释
注释: 先CTRL+K,然后CTRL+C 取消注释: 先CTRL+K,然后CTRL+U
- ubuntu16.04安装LCM
1.sudo apt-get install build-essential autoconf automake autopoint libglib2.0-dev libtool openjdk-8- ...
- English trip V1 - B 21. On a busy day 忙碌的一天 Teacher:Taylor Key: at on in
In this lesson you will learn to tell the time. 说时间 课上内容(Lesson) at time; at 7:30; at midday; ...
- p1530 Fractions to Decimals
将余数记录下来,如果余数相同,那么商的下一位也相同. #include <iostream> #include <cstdio> #include <cmath> ...
- 前端Vue之vue的基本操作
1.1 vue.js的快速入门使用 vue.js是目前前端web开发最流行的工具库之一,由尤雨溪在2014年2月发布的. 另外几个常见的工具库:react.js /angular.js 官方网站: 中 ...
- Kay and Snowflake CodeForces - 685B (重心, 好题)
大意:给定有根树, 求每个子树的重心 我太菜了啊, 只能想到暴力树剖, 然而这就是个B题, 感觉树剖+线段树二分还是挺难写的..... 看了题解发现重心一定在重儿子与根的树链上, 重心最多上跳n-1次 ...
- windows下如何通过git bash获取gitlab ssh公钥
Gitlab1. 安装git,从程序目录打开 "Git Bash" 2. 键入命令:ssh-keygen -t rsa -C "email@email.com" ...