pytesseract 验证码识别
以下代码,如有不懂加群讨论
# *-* coding:utf-8 *-* #
import json
import requests
import pytesseract
import time
import datetime
from PIL import Image
from bs4 import BeautifulSoup
import urllib3
import random
import os def binarizing(img, threshold):
# input: gray image, get black and white images
pixdata = img.load()
w, h = img.size
for y in range(h):
for x in range(w):
if pixdata[x, y] < threshold:
pixdata[x, y] = 0
else:
pixdata[x, y] = 255
return img def depoint(img):
# input: gray image, remove the noise
pixdata = img.load()
w, h = img.size
for x in range(1, w - 1):
if x > 1 and x != w - 2:
# 获取目标像素点左右位置
left = x - 1
right = x + 1 for y in range(1, h - 1):
# 获取目标像素点上下位置
up = y - 1
down = y + 1 if x <= 2 or x >= (w - 2):
img.putpixel((x, y), 255) elif y <= 2 or y >= (h - 2):
img.putpixel((x, y), 255) elif img.getpixel((x, y)) == 0:
if y > 1 and y != h - 1: # 以目标像素点为中心点,获取周围像素点颜色
# 0为黑色,255为白色
up_color = img.getpixel((x, up))
down_color = img.getpixel((x, down))
left_color = img.getpixel((left, y))
left_down_color = img.getpixel((left, down))
right_color = img.getpixel((right, y))
right_up_color = img.getpixel((right, up))
right_down_color = img.getpixel((right, down))
# 去除竖线干扰线
if down_color == 0:
if left_color == 255 and left_down_color == 255 and \
right_color == 255 and right_down_color == 255:
img.putpixel((x, y), 255) # 去除横线干扰线 elif right_color == 0:
if down_color == 255 and right_down_color == 255 and \
up_color == 255 and right_up_color == 255:
img.putpixel((x, y), 255) # 去除斜线干扰线
if left_color == 255 and right_color == 255 \
and up_color == 255 and down_color == 255:
img.putpixel((x, y), 255) return img def get_code():
'''
下载验证码并pytesseract 识别验证码
:return:
'''
code_file = '1.jpg'
image = Image.open(code_file)
image.show()
#text = input('请输入验证码:')
image = image.convert("L")
binarizing(image, 110)
depoint(image)
image.show() text = pytesseract.image_to_string(image)
return text def get_xsrf():
code = get_code()
print (code) if __name__ == '__main__':
get_xsrf()


pytesseract 验证码识别的更多相关文章
- Python之selenium+pytesseract 实现识别验证码自动化登录脚本
今天写自己的爆破靶场WP时候,遇到有验证码的网站除了使用pkav的工具我们同样可以通过py强大的第三方库来实现识别验证码+后台登录爆破,这里做个笔记~~~ 0x01关于selenium seleniu ...
- python3使用pytesseract进行验证码识别
pytesseract介绍 1.Python-tesseract是一个基于google's Tesseract-OCR的独立封装包: 2.Python-tesseract功能是识别图片文件中文字,并作 ...
- Selenium&Pytesseract模拟登录+验证码识别
验证码是爬虫需要解决的问题,因为很多网站的数据是需要登录成功后才可以获取的. 验证码识别,即图片识别,很多人都有误区,觉得这是爬虫方面的知识,其实是不对的. 验证码识别涉及到的知识:人工智能,模式识别 ...
- Selenium&Pytesseract模拟登录+验证码识别
验证码是爬虫需要解决的问题,因为很多网站的数据是需要登录成功后才可以获取的. 验证码识别,即图片识别,很多人都有误区,觉得这是爬虫方面的知识,其实是不对的. 验证码识别涉及到的知识:人工智能,模式识别 ...
- Python 3.6 版本-使用Pytesseract 模块进行图像验证码识别
环境: (1) win7 64位 (2) Idea (3) python 3.6 (4) pip install pillow < >pip install pytesse ...
- python验证码识别
关于利用python进行验证码识别的一些想法 用python加“验证码”为关键词在baidu里搜一下,可以找到很多关于验证码识别的文章.我大体看了一下,主要方法有几类:一类是通过对图片进行处 理,然后 ...
- python识别验证码——一般的数字加字母验证码识别
1.验证码的识别是有针对性的,不同的系统.应用的验证码区别有大有小,只要处理好图片,利用好pytesseract,一般的验证码都可以识别 2.我在识别验证码的路上走了很多弯路,重点应该放在怎么把图片处 ...
- python验证码识别接口及识别思路代码
1,验证码识别接口代码 import json import base64 import requests def shibie(): data = {} path = "./img/&qu ...
- Python图像处理之验证码识别
在上一篇博客Python图像处理之图片文字识别(OCR)中我们介绍了在Python中如何利用Tesseract软件来识别图片中的英文与中文,本文将具体介绍如何在Python中利用Tesseract ...
随机推荐
- linux中日历命令显示
cal 显示当前月的日历 cal 年份 显示特定一年的年历 [jasmine.qian@]$ cal January 2019 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 ...
- Oracle(字符函数)
单行函数语法: 语法:funcation_name(列 | 表达式[, 参数1, 参数2]) 单行函数主要分为以下几种: 字符函数:接收数据返回具体的字符信息 数值函数:对数字进行处理,例如:四舍五入 ...
- Http请求处理流程 管道流程 MVC扩展HttpModule
HttpApplication 封装了管道处理请求的所有事件 HttpModule 对HttpApplication中事件的扩展 HttpHandler 处理程序 每个请求都要经过Handle ...
- VMware安装Linux并配置网络通信
说明: Linux系统:CentOS-6.8-x86_64-minimal.iso VMware版本:9.0 首先下载VMware并安装.然后将CentOS-6.8-x86_64-minimal.is ...
- 数据库:Mysql中“select ... for update”排他锁分析
Mysql InnoDB 排他锁 用法: select … for update; 例如:select * from goods where id = 1 for update; 排他锁的申请前提:没 ...
- 雷林鹏分享:jQuery EasyUI 窗口 - 窗口与布局
jQuery EasyUI 窗口 - 窗口与布局 Layout 组件可以内嵌在窗口(window)中.我们可以创建一个复杂的布局窗口,甚至不需要写任何的 js 代码.jquery-easyui 框架帮 ...
- 雷林鹏分享:现实生活中的 XML
现实生活中的 XML 如何使用 XML 来交换信息的一些实例. 实例:XML 新闻 XMLNews 是用于交换新闻和其他信息的规范. 对新闻的供求双方来说,通过使用这种标准,可以使各种类型的新闻信息通 ...
- 【转】 详解C中volatile关键字
转自: http://www.cnblogs.com/yc_sunniwell/archive/2010/06/24/1764231.html volatile提醒编译器它后面所定义的变量随时都有可能 ...
- English trip V1 - 23. Big and Bigger Teacher:Corrine Key: adjective comparisons 形容词 比较级
In this lesson you will learn to make comparisons. 课上内容(Lesson) compare n. 比较 vt. 比拟,喻为:[语]构成 vi ...
- C#生成XSD规范
首先在开始菜单中找到:Visual Studio 2005 命令提示 大柏树按:VS2010在:开始—> Microsoft Visual Studio 2010 —> Visual St ...