zoukankan      html  css  js  c++  java
  • Tesseract处理背景渐变的图片

    在Tesseract处理背景渐变图片不太理想的情况下, 可以利用Pillow库, 创建一个阈值过滤器来去掉渐变的背景色, 只把文字留下来, 从而让图片更清晰, 便于Tesseract读取:

     1 from PIL import Image
     2 import subprocess
     3 
     4 def cleanFile(filePath, newFilePath):
     5     image = Image.open(filePath)
     6 
     7     # 对图片进行阈值过滤, 然后保存
     8     image = image.point(lambda x: 0 if x<143 else 255)
     9     image.save(newFilePath)
    10 
    11     # 调用系统的tesseract命令对图片进行ocr识别
    12     # subprocess.call(["tesseract", newFilePath, "output"])  //报错:文件找不到
    13     subprocess.call(["C:/Program Files (x86)/Tesseract-OCR/tesseract", newFilePath, "output"])
    14 
    15     # 打开文件读取结果
    16     outputFile = open("output.txt", 'r')
    17     print(outputFile.read())
    18     outputFile.close()
    19 
    20 cleanFile("text_2.png", "text_2_clean.png")

    以下两张图片分别为text_2.png和text_2_clean.png

  • 相关阅读:
    获取deeplearning电子书
    iterm2 粘贴时有多余字符 0~ 1~
    linux mint使用中的问题解决记录
    column命令
    命令行中画图
    sphinx转pdf显示中文
    linux查看显卡
    python 3.6
    Mac笔记本中使用postgresql
    计算KS值的标准代码
  • 原文地址:https://www.cnblogs.com/CoolJayson/p/7352129.html
Copyright © 2011-2022 走看看