python简单的图像识别

将图像翻译成文字称为光学文字识别(Optical Character Recognition,OCR)
OCR库
Pillow,Tesseract,NumPy.
利用Pillow库,创建一个过滤器来去掉渐变的背景色,只把文字留下来。

from PIL import Image
import subprocess

def cleanFile(filePath,newFilePath):
    image = Image.open(filePath)

    #对图片进行过滤,然后保存
    image = image.point(lamba x:0 if x<143 else 255)
    image.save(newFilePath)
    #调用系统的tesseract命令对图片进行OCR识别
    subprecess.call(['tesseract',newFilePath,'output'])
    #打开文件读取结果
    outputFile = open('output.txt','r')
    print(outputFile.read())
    outputFile.close()
cleanFile('text_2,jpg','text_2_clean.png')

“`

猜你喜欢

转载自blog.csdn.net/qq_40965177/article/details/81413591