码迷,mamicode.com
首页 > 编程语言 > 详细

[Python]图像二值化

时间:2020-03-03 19:13:19      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:png   pen   das   数字   int   其他   rom   tps   log   

https://blog.csdn.net/qq_35531549/article/details/96134760

 

# 识别前处理
# 图片二值化
from PIL import Image
import os
os.chdir(‘D:\OCR‘)
img = Image.open(‘test.png‘)

# 模式L”为灰色图像,它的每个像素用8个bit表示,0表示黑,255表示白,其他数字表示不同的灰度。
Img = img.convert(‘L‘)
Img.save("test1.png")

# 自定义灰度界限,大于这个值为黑色,小于这个值为白色
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("test2.png")
# 识别图片内容
import pytesseract
img_path = ‘test2.png‘

text=pytesseract.image_to_string(Image.open(img_path))

print(text)

————————————————
版权声明:本文为CSDN博主「寸草心2130」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_35531549/article/details/96134760

[Python]图像二值化

标签:png   pen   das   数字   int   其他   rom   tps   log   

原文地址:https://www.cnblogs.com/shanlinghan/p/12403909.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!