【发布时间】:2021-11-18 20:44:54
【问题描述】:
我正在做一个文档阅读器,它将其中的所有文本解析为谷歌电子表格,这个脚本应该可以节省我的工作时间,问题是二进制图像有很多噪音(文本周围的小点)这让 pytesseract 感到困惑。我怎样才能消除这种噪音?我用来二值化图像的代码是:
import pytesseract
import cv2
import numpy as np
import os
import re
import argparse
#binarization of images
def binarize(img):
#convert image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#apply adaptive thresholding
thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)
#return thresholded image
return thresh
#construct argument parser
parser = argparse.ArgumentParser(description='Binarize image and parse text in image to string')
parser.add_argument('-i', '--image', help='path to image', required=True)
parser.add_argument('-o', '--output', help='path to output file', required=True)
args = parser.parse_args()
# load image
img = cv2.imread(args.image)
#binarization of image
thresh = binarize(img)
#show image
cv2.imshow('image', thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()
#save image
cv2.imwrite(args.output+'/imagen3.jpg', thresh)
哪个比哪个都差
【问题讨论】:
-
在你的
adaptiveThreshold,你试过不同的参数吗?您的结果看起来没有正确使用adaptiveThreshold -
我该如何改进它们?我需要用不同的 C 值发短信吗?但它不会把代码变成手动的吗?我的意思是如果图像有不同的阴影或类似的东西,我需要改变这个值吗?
-
为什么要黑白图像?您正在寻找缩小图像的尺寸吗?
-
是用pytesseract读取图片中的文字
标签: python opencv image-processing tesseract python-tesseract