【发布时间】:2018-08-13 09:04:39
【问题描述】:
我需要使用opencv 在以下图像中查找框。我曾尝试使用 mser,但没有得到任何好的结果。
我的 MSER 代码:
mser = cv2.MSER_create()
img = cv2.imread('Lines.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
I = img.copy()
regions, _ = mser.detectRegions(I)
hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]
mask = np.zeros((img.shape[0], img.shape[1], 1), dtype=np.uint8)
c=0
points=[]
for contour in hulls:
[x, y, w, h] = cv2.boundingRect(contour)
if w < 50 or h < 8 or w>120:
continue
c=c+1
cv2.rectangle(I, (x, y), (x + w, y + h), (255, 0, 255), 0)
plt.figure(1,figsize=(100, 50))
plt.imshow(I)
MSER 的结果:
【问题讨论】:
-
既然你已经有一个二值图像,我会尝试
cv::findContours并只保留可以简化的轮廓,例如Douglas-Peucker 算法使用 4 个点。我有一个代码,但仅限于 C++。 -
在python中可以使用cv2.findContours函数
标签: python opencv image-processing deep-learning computer-vision