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
原文地址:https://www.cnblogs.com/star-py-blog/p/13756827.html