首页 > 编程语言 > 详细

python图片二值化提高识别率

时间:2019-08-24 00:45:42      阅读:118      评论:0      收藏:0      [点我收藏+]

  

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‘)

 

 

原图:

技术分享图片

处理过后的图:

技术分享图片

 

识别结果:

技术分享图片

 

python图片二值化提高识别率

原文:https://www.cnblogs.com/codeDevotee/p/11403096.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!