opencv python3 文本区域识别_使用Python和OpenCV3检测流程图中的文本区域
我正在尝试识别图像中包含文本的部分。为此,我首先使用OpenCV(v.3)对图像进行预处理,然后将矩形/方框添加到文本部分。在我下面的代码确实报告了一些轮廓。请参阅下面的代码、输入图像和输出。在代码:import os,sys,cv2,pytesseract## IMAGEafile= "test-small.jpg"def reader(afile):aimg...
我正在尝试识别图像中包含文本的部分。为此,我首先使用OpenCV(v.3)对图像进行预处理,然后将矩形/方框添加到文本部分。在
我下面的代码确实报告了一些轮廓。请参阅下面的代码、输入图像和输出。在
代码:import os,sys,cv2,pytesseract
## IMAGE
afile = "test-small.jpg"
def reader(afile):
aimg = cv2.imread(afile,0)
print("Image Shape%s | Size:%s" % (aimg.shape,aimg.size))
return aimg
def boundbox(aimg):
out_path2 = "%s-tagged.jpg" % (afile.rpartition(".")[0])
ret,thresh = cv2.threshold(aimg,127,255,0)
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
acount = 0
for contour in contours:
acount+=1
x, y, w, h = cv2.boundingRect(contour)
print("Coordinates",x,y,w,h)
if w < 100 and h < 100: ## Avoid tagging small objects i.e. false positives
continue
cv2.rectangle(aimg, (x, y), (x + w, y + h), (255, 0, 0), 8) ##
print("Total contours found:%s" % (acount))
cv2.imwrite(out_path2,aimg)
return out_path2
def main():
aimg = reader(afile)
bimg = boundbox(aimg)
if __name__ == '__main__':
main()
测试图像:
输出:
问题是:(1)矩形在图像上不可见,(2)文本部分的检测不准确。如何改进上述代码以检测文本部分?在
谢谢你的帮助。在
巴德
更多推荐
所有评论(0)