zoukankan      html  css  js  c++  java
  • 使用pytesseract提取图片文字

    效果展示:

    (原始图片)

    (运行结果)

     代码示例:

    # -*- coding:utf-8 -*-
    from PIL import Image
    import pytesseract
    
    
    def cleanFile(filePath, newFilePath):
        image = Image.open(filePath)
    
        # 对图片进行阈值过滤(低于143的置为黑色,否则为白色)
        # 相当于对电脑显卡调节对比度(电脑显卡对比度默认为50,我比较习惯于调成53)
        image = image.point(lambda x: 0 if x < 143 else 255)
        # 重新保存图片
        image.save(newFilePath)
    
        image = Image.open(newFilePath)
        text = pytesseract.image_to_string(image, lang='chi_sim')
        print(text)
    
    
    if __name__ == "__main__":
        url = r"D:图片励志图片666.png"
        new_url = r"D:图片励志图片777.png"
        cleanFile(url, new_url)
  • 相关阅读:
    gdb调试
    go pipeline
    Go的Timer
    goconvey
    购物
    Go的可行测试
    可能会停止一段时间的更新
    一些blog
    linux全套 | Python开发平台_Ubuntu | 15
    Python基础 | 配置pip镜像源 | 01
  • 原文地址:https://www.cnblogs.com/shun7man/p/14425931.html
Copyright © 2011-2022 走看看