日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python图片识别验证码软件_python识别图片验证码

發布時間:2023/12/10 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python图片识别验证码软件_python识别图片验证码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://robertgawron.blogspot.hk/2010/11/almost-all-sites-use-images-with-text.html

圖片的識別主要有,去色,減噪,去線,分割,二值化,提取特征碼

這里比較方便的是使用tesseract

1,準備庫

apt-get install python-imaging

pip install Pillow

apt-get install tesseract-ocr

apt-get -f iinstall

wget https://python-tesseract.googlecode.com/files/python-tesseract_0.8-1.5_i386.deb

dpkg -i?python-tesseract_0.8-1.5_i386.deb

2,圖片處理

這里用到Pillow代替PIL,import改成

from PIL import Image,ImageFilter

用法 XXX.py XX.jpg 100

import sys

import Image

import ImageFilter

def prepare_image(img):

"""Transform image to greyscale and blur it"""

img = img.filter(ImageFilter.SMOOTH_MORE)

img = img.filter(ImageFilter.SMOOTH_MORE)

if 'L' != img.mode:

img = img.convert('L')

return img

def remove_noise(img, pass_factor):

for column in range(img.size[0]):

for line in range(img.size[1]):

value = remove_noise_by_pixel(img, column, line, pass_factor)

img.putpixel((column, line), value)

return img

def remove_noise_by_pixel(img, column, line, pass_factor):

if img.getpixel((column, line)) < pass_factor:

return (0)

return (255)

if __name__=="__main__":

input_image = sys.argv[1]

output_image = 'out_' + input_image

pass_factor = int(sys.argv[2])

img = Image.open(input_image)

img = prepare_image(img)

img = remove_noise(img, pass_factor)

img.save(output_image)

3,識別

這里用到開源OCR庫tesseract

開源的軟件免費,但相對的說明文件就不足,只有自己查代碼

因為驗證碼一般只有一行,這個

api.SetPageSegMode(tesseract.PSM_AUTO)

改成

api.SetPageSegMode(7)

import tesseract

api = tesseract.TessBaseAPI()

api.Init(".","eng",tesseract.OEM_DEFAULT)

api.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyz")

api.SetPageSegMode(tesseract.PSM_AUTO)

mImgFile = "eurotext.jpg"

mBuffer=open(mImgFile,"rb").read()

result = tesseract.ProcessPagesBuffer(mBuffer,len(mBuffer),api)

print "result(ProcessPagesBuffer)=",result

總結

以上是生活随笔為你收集整理的python图片识别验证码软件_python识别图片验证码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。