1

我有这张图片:

在此处输入图像描述

我想提取所有按钮并将它们保存在不同的图像中。直到现在我有这个代码:

import numpy as np
import cv2

img = cv2.imread('C:\\Users\\Rita\\Desktop\\ISCTE\\2_ano\\Tese\MSER\\1_Exemplo\\botoes.PNG',1)

vis = img.copy()
mser = cv2.MSER_create()
vis = img.copy()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

regions, _ = mser.detectRegions(gray)

hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]
cv2.polylines(vis, hulls, 1, (0, 255, 0))



for i, contour in enumerate(hulls):
    x,y,w,h = cv2.boundingRect(contour)
    cv2.imwrite('1_exemplo_{}.png'.format(i), img[y:y+h,x:x+w])

但它并没有以正确的方式分开。有人知道我在代码中缺少什么吗?或者最好的方法是什么?

4

1 回答 1

1

为了提取所需的内容,您必须尝试不同的参数。

使用下面的片段,我提取了除一个 blob 之外的所有内容:

mser = cv2.MSER_create( _min_area = 5000, _max_variation = 1.0)

在此处输入图像描述

尝试更改此链接中的其他参数以获得更好的结果。

于 2018-04-23T08:09:09.337 回答