zoukankan      html  css  js  c++  java
  • Python验证码通过pytesser识别

    Python安装包:

    需要安装的包主要有两个: PIL 和 pytesser 、tesseract

    (1)、安装PIL:下载地址:http://www.pythonware.com/products/pil/

    下载后是一个exe程序,直接双击安装

    (2)、pytesser:下载地址:http://code.google.com/p/pytesser/

    pytesser 模块的安装:

    下载后得到 “pytesser.zip”,是一个压缩文件,使用方法: 

    1、在 “C:Python27Libsite-packages” 路径下新建一个文件夹,命名 “pytesser” 。把 “pytesser.zip” 里的文件解压到该目录:

    2、将 “pytesser.py” 改名为 “__init__.py”。

    3、打开 “__init__.py” 文件,修改:tesseract_exe_name = 'C:\Python27\Lib\site-packages\pytesser\tesseract' # Name of executable to be called at command line

    4、pytesser 模块依赖于 PIL 模块,如果是按照上面的方法安装 PIL 的话,需要把 “init.py” 文件里的 “import Image” 改成 “from PIL import Image” 。

    下载解压后直接放C:Python27Libsite-packages,同时,新建一个pytesser.pth,内容就写,注意这里的内容一定要和pytesser这个文件夹同名,意思就是pytesser文件夹,pytesser.pth,及内容都要一样!

    (3)、Tesseract OCR engine下载:http://code.google.com/p/tesseract-ocr/

    下载后解压,tessdata文件夹,用其替换掉pytesser解压后的tessdata文件夹即可。(就上面的pytesser文件夹)

    代码如下:

    1 #-*- coding:utf-8 -*-
    2 __author__ = "carry"
    3 from PIL import Image
    4 from pytesser import *
    5 
    6 image = Image.open('xx.jpg')
    7 print image_to_string(image)

  • 相关阅读:
    经典算法之七大排序
    Memcached在Asp.NET中的使用
    利用memcached构建高性能的Web应用程序(转)
    C# 反射机制
    数据库事务设置保存点
    C# 串口通信总结
    某投注网站的BUG
    浙江电信网上营业厅的一个BUG(有更新)
    解决DESCryptoServiceProvider加解密时弱密钥异常
    ASP.NET自定义控件开发示例(二)
  • 原文地址:https://www.cnblogs.com/lxs1314/p/7223347.html
Copyright © 2011-2022 走看看