微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python图片二值化提高识别率

 
 

  

import cv2
from PIL import Image
from PyTesseract import PyTesseract
from PIL import ImageEnhance
import re
import string



def
createFile(filePath,newFilePath): img = Image.open(filePath) # 模式L”为灰色图像,它的每个像素用8个bit表示,0表示黑,255表示白,其他数字表示不同的灰度。 Img = img.convert(L) Img.save(newFilePath) # 自定义灰度界限,大于这个值为黑色,小于这个值为白色 threshold = 200 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) # 图片二值化 photo = Img.point(table,1) photo.save(newFilePath)

if __name__ == ‘__main__‘:

createFile(r‘1.bmp‘,r‘newTest.png‘)

 

 

原图:

分享图片

处理过后的图:

分享图片

 

识别结果:

分享图片

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐