python简单验证码识别的简单介绍

本文目录一览:

python验证码识别

orc文字识别,现在比较流行的是通过人工智能训练CNN神经网络来识别。

大体流程

准备训练数据。训练数据可以自己写个程序生成验证码,和标准答案。

构建CNN模型。这个比较简单,使用keras框架,5分钟的事情。

训练。不停地把数据feed给程序,直到准确率达到你的期望,推荐使用GPU加速

预测。加载模型,把验证码图片feed给模型,得出结果

希望对你有帮助。

如何利用Python做简单的验证码识别

最简单的是这个:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

#!/usr/bin/python3.4

# -*- coding: utf-8 -*-

# 1、pip3 install pyocr

# 2、pip3 install pillow or easy_install Pillow

# 3、安装tesseract-ocr:,安装在C:\Program Files\下

# 4、要求python默认安装在C盘

# 代码:

# !/usr/bin/python3.4

# -*- coding: utf-8 -*-

import pytesseract

from PIL import Image

image = Image.open(‘../jpg/code.png’)

code = pytesseract.image_to_string(image)

print(code)

如何python爬虫识别验证码

在用爬虫爬取网站数据时,有些站点的一些关键数据的获取需要使用账号登录,这里可以使用requests发送登录请求,并用Session对象来自动处理相关Cookie。

另外在登录时,有些网站有时会要求输入验证码,比较简单的验证码可以直接用pytesser来识别,复杂的验证码可以依据相应的特征自己采集数据训练分类器。

以CSDN网站的登录为例,这里用Python的requests库与pytesser库写了一个登录函数。如果需要输入验证码,函数会首先下载验证码到本地,然后用pytesser识别验证码后登录,对于CSDN登录验证码,pytesser的识别率很高。

如何使用python识别验证码

第一种,将验证码保存本地,然后手动输入。

第二种,外包给验证码识别公司

第三种,学习算法识别

如何利用Python 做验证码识别

#!/usr/bin/python3.4

# -*- coding: utf-8 -*-

 

# 1、pip3 install pyocr

# 2、pip3 install pillow or easy_install Pillow

# 3、安装tesseract-ocr:,安装在C:\Program Files\下

# 4、要求python默认安装在C盘

# 代码:

# !/usr/bin/python3.4

# -*- coding: utf-8 -*-

 

import pytesseract

from PIL import Image

 

image = Image.open(‘../jpg/code.png’)

code = pytesseract.image_to_string(image)

print(code)

python怎样调用第三方平台识别验证码

一、pytesseract介绍

1、pytesseract说明

pytesseract最新版本0.1.6,网址:h

Python-tesseract is a wrapper for google’s Tesseract-OCR

( ht-ocr/ ). It is also useful as a

stand-alone invocation script to tesseract, as it can read all image types

supported by the Python Imaging Library, including jpeg, png, gif, bmp, tiff,

and others, whereas tesseract-ocr by default only supports tiff and bmp.

Additionally, if used as a script, Python-tesseract will print the recognized

text in stead of writing it to a file. Support for confidence estimates and

bounding box data is planned for future releases.

翻译一下大意:

a、Python-tesseract是一个基于google’s Tesseract-OCR的独立封装包;

b、Python-tesseract功能是识别图片文件中文字,并作为返回参数返回识别结果;

c、Python-tesseract默认支持tiff、bmp格式图片,只有在安装PIL之后,才能支持jpeg、gif、png等其他图片格式;

2、pytesseract安装

INSTALLATION:

Prerequisites:

* Python-tesseract requires python 2.5 or later or python 3.

* You will need the Python Imaging Library (PIL). Under Debian/Ubuntu, this is

the package “python-imaging” or “python3-imaging” for python3.

* Install google tesseract-ocr from hsseract-ocr/ .

You must be able to invoke the tesseract command as “tesseract”. If this

isn’t the case, for example because tesseract isn’t in your PATH, you will

have to change the “tesseract_cmd” variable at the top of ‘tesseract.py’.

Under Debian/Ubuntu you can use the package “tesseract-ocr”.

Installing via pip: 

See the [pytesseract package page](hi/pytesseract) 

“`

$ sudo pip install pytesseract

翻译一下:

a、Python-tesseract支持python2.5及更高版本;

b、Python-tesseract需要安装PIL(Python Imaging Library) ,来支持更多的图片格式;

c、Python-tesseract需要安装tesseract-ocr安装包,具体参看上一篇博文。

综上,Pytesseract原理:

1、上一篇博文中提到,执行命令行 tesseract.exe 1.png output -l eng ,可以识别1.png中文字,并把识别结果输出到output.txt中;

2、Pytesseract对上述过程进行了二次封装,自动调用tesseract.exe,并读取output.txt文件的内容,作为函数的返回值进行返回。

二、pytesseract使用

USAGE:

“`

try:

import Image

except ImportError:

from PIL import Image

import pytesseract

print(pytesseract.image_to_string(Image.open(‘test.png’)))

print(pytesseract.image_to_string(Image.open(‘test-european.jpg’),))

可以看到:

1、核心代码就是image_to_string函数,该函数还支持-l eng 参数,支持-psm 参数。

用法:

image_to_string(Image.open(‘test.png’),lang=”eng” config=”-psm 7″)

2、pytesseract里调用了image,所以才需要PIL,其实tesseract.exe本身是支持jpeg、png等图片格式的。

实例代码,识别某公共网站的验证码(大家千万别干坏事啊,思虑再三,最后还是隐掉网站域名,大家去找别的网站试试吧……):

 View Code

三、pytesseract代码优化

上述程序在windows平台运行时,会发现有黑色的控制台窗口一闪而过的画面,不太友好。

略微修改了pytesseract.py(C:\Python27\Lib\site-packages\pytesseract目录下),把上述过程进行了隐藏。

# modified by zhongtang hide console window

# new code

IS_WIN32 = ‘win32’ in str(sys.platform).lower()

if IS_WIN32:

startupinfo = subprocess.STARTUPINFO()

startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

startupinfo.wShowWindow = subprocess.SW_HIDE

proc = subprocess.Popen(command,

stderr=subprocess.PIPE,startupinfo=startupinfo)

”’

# old code

proc = subprocess.Popen(command,

stderr=subprocess.PIPE)

”’

# modified end

为了方便初学者,把pytesseract.py也贴出来,高手自行忽略。

 View Code

原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/237395.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
小蓝小蓝
上一篇 2024-12-12 12:04
下一篇 2024-12-12 12:05

相关推荐

  • Python周杰伦代码用法介绍

    本文将从多个方面对Python周杰伦代码进行详细的阐述。 一、代码介绍 from urllib.request import urlopen from bs4 import Bea…

    编程 2025-04-29
  • Python列表中负数的个数

    Python列表是一个有序的集合,可以存储多个不同类型的元素。而负数是指小于0的整数。在Python列表中,我们想要找到负数的个数,可以通过以下几个方面进行实现。 一、使用循环遍历…

    编程 2025-04-29
  • 如何查看Anaconda中Python路径

    对Anaconda中Python路径即conda环境的查看进行详细的阐述。 一、使用命令行查看 1、在Windows系统中,可以使用命令提示符(cmd)或者Anaconda Pro…

    编程 2025-04-29
  • Python中引入上一级目录中函数

    Python中经常需要调用其他文件夹中的模块或函数,其中一个常见的操作是引入上一级目录中的函数。在此,我们将从多个角度详细解释如何在Python中引入上一级目录的函数。 一、加入环…

    编程 2025-04-29
  • Python计算阳历日期对应周几

    本文介绍如何通过Python计算任意阳历日期对应周几。 一、获取日期 获取日期可以通过Python内置的模块datetime实现,示例代码如下: from datetime imp…

    编程 2025-04-29
  • Python字典去重复工具

    使用Python语言编写字典去重复工具,可帮助用户快速去重复。 一、字典去重复工具的需求 在使用Python编写程序时,我们经常需要处理数据文件,其中包含了大量的重复数据。为了方便…

    编程 2025-04-29
  • python强行终止程序快捷键

    本文将从多个方面对python强行终止程序快捷键进行详细阐述,并提供相应代码示例。 一、Ctrl+C快捷键 Ctrl+C快捷键是在终端中经常用来强行终止运行的程序。当你在终端中运行…

    编程 2025-04-29
  • Python清华镜像下载

    Python清华镜像是一个高质量的Python开发资源镜像站,提供了Python及其相关的开发工具、框架和文档的下载服务。本文将从以下几个方面对Python清华镜像下载进行详细的阐…

    编程 2025-04-29
  • Python程序需要编译才能执行

    Python 被广泛应用于数据分析、人工智能、科学计算等领域,它的灵活性和简单易学的性质使得越来越多的人喜欢使用 Python 进行编程。然而,在 Python 中程序执行的方式不…

    编程 2025-04-29
  • 蝴蝶优化算法Python版

    蝴蝶优化算法是一种基于仿生学的优化算法,模仿自然界中的蝴蝶进行搜索。它可以应用于多个领域的优化问题,包括数学优化、工程问题、机器学习等。本文将从多个方面对蝴蝶优化算法Python版…

    编程 2025-04-29

发表回复

登录后才能评论