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)
运行结果: