python+pytesseract识别图片文字

此文只介绍一下python+pytesseract识别一些简单图片的数字,字母和汉字。如图1

import pytesseract
from PIL import Image,ImageEnhance
img=Image.open(r'F:\Test\test1.png')

#修改图片的灰度,提高识别准确性
img=img.convert('RGB')
enhancer=ImageEnhance.Color(img)
enhancer=enhancer.enhance(0)
enhancer=ImageEnhance.Brightness(enhancer)
enhancer=enhancer.enhance(2)
enhancer=ImageEnhance.Contrast(enhancer)
enhancer=enhancer.enhance(8)
enhancer=ImageEnhance.Sharpness(enhancer)
img=enhancer.enhance(20)

code=pytesseract.image_to_string(img)
print(code)

运行结果:

 

posted @ 2022-09-09 10:39  沐小木  Views(660)  Comments(0Edit  收藏  举报