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 ...
随机推荐
- Centos7 linux下通过源码安装redis以及使用
下载redis安装包 wget http://download.redis.io/releases/redis-5.0.3.tar.gz 解压压缩包 tar -zxvf redis-.tar.gz y ...
- 小程序scss页面布局
html <view class="main"> <form bindsubmit="feedback"> <textarea c ...
- cookie的常用操作
cookie介绍: 1. cookie的简单介绍就是把用户的登录信息缓存在本机的浏览器中,且最大容量为4KB, 2. 这种存储是不安全的,通常一般会进行加密处理,但是依旧不能做到安全,所以一般要优先考 ...
- C#连接数据库open函数失败
错误信息:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. (provider ...
- 前端调用接口报错看不到报错响应时 console.dir
console.dir() 可以看到很多.log看不到的属性和方法
- HDU 2569(简单的递推)
彼岸 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- 学习笔记25—python基本运算法则
1.矩阵的点乘: a*b, 矩阵乘法:dot(a*b),矩阵的次方:a**num (num = 2,表示2次)2.数组的并集,交集: >>> a = [1,2,3] >> ...
- 日志log4cxx 封装、实例讲解、配置文件log4cxx.properties
日志log4cxx 封装.实例讲解.配置文件log4cxx.properties 1. 日志作用 程序运行过程中,需要记录程序中的运行状况,方便排查问题,记录数据.可以根据日志的记录快速定位错误发生的 ...
- 大数据新手之路三:安装Kafka
Ubuntu16.04+Kafka1.0.0 1.下载kafka_2.11-1.0.0.tgz http://kafka.apache.org/downloads 2.解压到/usr/local/ka ...
- c# DataTable 序列化json
if (ds.Tables[0].Rows.Count != 0) { var list = GetJsonString(ds ...