zoukankan      html  css  js  c++  java
  • [Python]图像二值化

    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

  • 相关阅读:
    day04 Java Web 开发入门
    day0203 XML 学习笔记
    canvas 基础
    TreeSet
    IntelliJ IDEA
    elastic-job-lite
    Spring 同一接口注入多个bean实现
    StringRedisTemplate
    小记
    linux 命令
  • 原文地址:https://www.cnblogs.com/shanlinghan/p/12403909.html
Copyright © 2011-2022 走看看