【发布时间】:2019-09-12 16:13:43
【问题描述】:
我正在对文档图像进行 OCR。我想检测所有图片并从文档图像中删除。我想在文档图像中保留表格。一旦我检测到图片,我将删除然后想要 OCR。我试图找到轮廓试图检测所有更大的区域。不幸的是,它也检测到表格。还如何删除在文档图像中保留其他数据的对象。我正在使用 opencv 和 python
这是我的代码
import os
from PIL import Image
import pytesseract
img = cv2.imread('block2.jpg' , 0)
mask = np.ones(img.shape[:2], dtype="uint8") * 255
ret,thresh1 = cv2.threshold(img,127,255,0)
contours, sd = cv2.findContours(thresh1,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
areacontainer = []
for cnt in contours:
area = cv2.contourArea(cnt)
areacontainer.append(area)
avgArea = sum(areacontainer)/len(areacontainer)
[enter code here][1]
for c in contours:# average area heuristics
if cv2.contourArea(c)>6*avgArea:
cv2.drawContours(mask, [c], -1, 0, -1)
binary = cv2.bitwise_and(img, img, mask=mask) # subtracting
cv2.imwrite("bin.jpg" , binary)
cv2.imwrite("mask.jpg" , mask)
【问题讨论】:
-
请问什么是“文档图像”?您还应该展示您尝试过的代码并提供所有材料,以便人们可以运行您的代码并更正/改进它。请参阅最小完整可验证示例stackoverflow.com/help/minimal-reproducible-example
-
我已经添加了输入图片
标签: python image opencv image-processing computer-vision