【发布时间】:2020-10-25 13:32:33
【问题描述】:
我有这张图片:raw
我想从这张图片中删除方括号。我已经来了这么远:
# Import packages
import cv2
import numpy as np
#Create MSER object
mser = cv2.MSER_create()
#Your image path i-e receipt path
img = cv2.imread('uky.JPG')
#Convert to gray scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
vis = img.copy()
#detect regions in gray scale image
regions, _ = mser.detectRegions(gray)
hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]
cv2.polylines(vis, hulls, 1, (0, 255, 0))
cv2_imshow(vis)
mask = np.zeros((img.shape[0], img.shape[1], 1), dtype=np.uint8)
for contour in hulls:
cv2.drawContours(mask, [contour], -1, (255, 255, 255), -1)
#this is used to find only text regions, remaining are ignored
text_only = cv2.bitwise_and(img, img, mask=mask)
cv2_imshow(text_only)
此代码的结果:detected
预期输出:expected
但我不知道如何删除方括号。我确信这是一个如此简单的问题,但由于我对 OpenCV 不熟悉,所以我几个小时都无法解决这个问题。
如果有人可以向我解释这一点,我会非常高兴。非常感谢您。
【问题讨论】:
-
我认为你需要使用shape detection(虽然我对openCV不太熟悉:))
标签: python numpy opencv image-processing computer-vision