返回顶部
扩大
缩小
大江东去,浪淘尽,千古风流人物。故垒西边,人道是,三国周郎赤壁。乱石穿空,惊涛拍岸,卷起千堆雪。江山如画,一时多少豪杰。遥想公瑾当年,小乔初嫁了,雄姿英发。羽扇纶巾,谈笑间,樯橹灰飞烟灭。故国神游,多情应笑我,早生华发。人生如梦,一尊还酹江月。

tesserocr 使用

tesserocr 使用:

简单识别:

import tesserocr 
from PIL import Image

image =  Image.open('code.jpg')
result = tesserocr.image_to_text(image)
print(result)

多余线条干扰:

处理步骤

处理步骤:
	1. 转灰度:
         Image对象的convert()方法参数传人L,即可将图片转化为灰度图像
            
    image  = image.convert('L')
    image.show()
    
    2. 图片进行二值化处理:
    
    image = image.convert('1')
    image.show()
    
	采用的是默认阔值127。不能直接转化原因,要将原图先转为灰度图像,然后再指定二值化阔    
    
    
image = image.convert('L')

threshold = 80
table = []
for i in range(256):
    if i < threshold:
        table.append(0)
    else:
    	table.append(1)
image = image.point(table,'1')
image.show()

-》 验证码中的线条已经去除,整个验证码变得黑向分明,重新识别验证码
import tesserocr 
from PIL import Image

image =  Image.open('code.jpg')
image = image.convert('L')

threshold = 127
table = []
for i in range(256):
    if i < threshold:
        table.append(0)
    else:
    	table.append(1)
image = image.point(table,'1')

result = tesseroct.image_to_text(image)
print(result)

--> 针对一些有干扰的图片,做一些灰度和二值化处理,会提高图片识别的正确度

项目地址:

代码地址为:https://github.comPython3WebSpider/CracklmageCod

posted on 2020-09-30 23:07  晨星_star  阅读(454)  评论(0编辑  收藏  举报

导航