初识python PIL与pytesser
2016-07-11 23:42
363 查看
1、关于安装pytesser,安装前要安装PIL,具体的文件下载可以翻墙到官网去
值得注意的问题是尽量保持一致,譬如windows下的PIL为32位的(PIL-1.1.7.win32-for-python2.7.exe)
所以Python的版本也尽量装32位的,不然可以会遇到麻烦。pytesser直接解压在Python27\Lib\site-packages\文件夹下即可
2、初步认识pytesser 与 PIL 的一些函数
分辨率为 100*25
文件名为 demo.jpg
对于上面的验证码,因为字符的大小不太一样所以分割就显的麻烦,其实这种验证码直接用库函数就可以solve。
def demo():
import Image
from pytesser import image_to_string
img = Image.open('demo.jpg') # open and read the image
img = img.convert('L') # convert to other pixel format
# img.save('demo_convert.jpg') # save image
photo = img.resize((200,65)) # Resize image
print image_to_string(photo) # identify image
# end
output>>
vj9vpu
其中
img = img.convert('L') # convert to other pixel format
photo = img.resize((200,65)) # Resize image
这两行代码很关键,
第一行除去了颜色(差不多图片二值化这样子,先可以这样理解)
第二性更改了图片的大小,并非所有的验证码都需要这样子更改,一般码比较密集的,像素比较低的建议更改,至于更改的大小就得看经验或者自己测试咯
值得注意的问题是尽量保持一致,譬如windows下的PIL为32位的(PIL-1.1.7.win32-for-python2.7.exe)
所以Python的版本也尽量装32位的,不然可以会遇到麻烦。pytesser直接解压在Python27\Lib\site-packages\文件夹下即可
2、初步认识pytesser 与 PIL 的一些函数
分辨率为 100*25
文件名为 demo.jpg
对于上面的验证码,因为字符的大小不太一样所以分割就显的麻烦,其实这种验证码直接用库函数就可以solve。
def demo():
import Image
from pytesser import image_to_string
img = Image.open('demo.jpg') # open and read the image
img = img.convert('L') # convert to other pixel format
# img.save('demo_convert.jpg') # save image
photo = img.resize((200,65)) # Resize image
print image_to_string(photo) # identify image
# end
output>>
vj9vpu
其中
img = img.convert('L') # convert to other pixel format
photo = img.resize((200,65)) # Resize image
这两行代码很关键,
第一行除去了颜色(差不多图片二值化这样子,先可以这样理解)
第二性更改了图片的大小,并非所有的验证码都需要这样子更改,一般码比较密集的,像素比较低的建议更改,至于更改的大小就得看经验或者自己测试咯
相关文章推荐
- 初识python PIL与pytesser
- 初识python PIL与pytesser
- 初识python PIL与pytesser
- 初识python PIL与pytesser
- 初识python PIL与pytesser
- 初识python PIL与pytesser
- 初识python PIL与pytesser
- 初识python PIL与pytesser
- 初识python PIL与pytesser
- 初识python PIL与pytesser
- Python+PyDev+Jdk+Eclipse开发环境部署
- 24 点 Python 的实现
- python学习第四天 --字符编码 与格式化及其字符串切片
- Python的函数
- Python 模块的快速安装
- python linecache模块读取文件的方法
- Python中协程(Coroutine)的使用和注意点
- python 时间模块学习
- 自己动手写word2vec (一):主要概念和流程
- Python学习笔记10:Python错误和异常