[Python]光学字符识别
number.png# pip install pytesseract# sudo apt-get install tesseract-ocr# python>>> import pytesseract>>> from PIL import Image>>> img = Image.open("/home/wq/Downloads/number.png")>>> pytesserac
·
number.png
# pip install pytesseract
# sudo apt-get install tesseract-ocr
# python
>>> import pytesseract
>>> from PIL import Image
>>> img = Image.open("/home/wq/Downloads/number.png")
>>> pytesseract.image_to_string(img)
u'1234567890'
处理机动车牌照上的数字
阈值化
>>> img.save('/home/wq/Downloads/94111.png')
>>> gray = img.convert('L')
>>> gray.save('/home/wq/Downloads/94111_gray.png')
处理后结果
>>> bw = gray.point(lambda x: 0 if x < 100 else 255, '1')
>>> bw.save('/home/wq/Downloads/94111_black.png')
处理后结果
>>> bw = bw.point(lambda x: 255-x, '1')
>>> bw.save('/home/wq/Downloads/94111_reverse.png')
处理后结果
识别数字
>>> pytesseract.image_to_string(bw)
u'4|_||'
T_T 很显然没有很好地识别出来,需要改进
更多推荐
已为社区贡献2条内容
所有评论(0)