加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python图片二值化提高识别率

发布时间:2020-12-20 10:53:40 所属栏目: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表示
 
 

  

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

?

?

原图:

处理过后的图:

?

识别结果:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读