
我想要检测所有文本框的网页视觉使用OpencV轮廓检测。但是在这里,它也是检测文本的,我需要过滤掉其他的结果,只检测到矩形框。
我只想要矩形检测框和按钮,并过滤掉所有其他检测的文本。
发布于 2019-07-27 04:56:26
使用下面的代码作为起点:
img = cv2.imread('amazon.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# inverse thresholding
thresh = cv2.threshold(gray, 195, 255, cv2.THRESH_BINARY_INV)[1]
# find contours
contours = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0]
mask = np.ones(img.shape[:2], dtype="uint8") * 255
for c in contours:
# get the bounding rect
x, y, w, h = cv2.boundingRect(c)
if w*h>1000:
cv2.rectangle(mask, (x, y), (x+w, y+h), (0, 0, 255), -1)
res_final = cv2.bitwise_and(img, img, mask=cv2.bitwise_not(mask))
cv2.imshow("boxes", mask)
cv2.imshow("final image", res_final)
cv2.waitKey(0)
cv2.destroyAllWindows()输出:
图1:原始图像:

图2:所需轮廓的掩码:

图3:在原始图像中检测到的轮廓(所需的):

https://stackoverflow.com/questions/57229066
复制相似问题