Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV MSER detection issue

I'm trying to separate the detected objects into images but since the MSER method are detecting too many times the boundaries when i save into images i get a lot of repetetive images.

This is the image with the MSER detection: MSER detection: C:\fakepath\GDFXn.png

So i want to separate each object into an image, without any repetitions. Is anyone can help me?

Thank you! Rita Maia

This is my code so far:

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

vis = img.copy() mser = cv2.MSER_create()

mser = cv2.MSER_create( _min_area = 5000, _max_area = 25000, _max_variation = 1.0) 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])

click to hide/show revision 2
None

updated 2018-05-22 05:42:46 -0600

berak gravatar image

OpenCV MSER detection issue

I'm trying to separate the detected objects into images but since the MSER method are detecting too many times the boundaries when i save into images i get a lot of repetetive images.

This is the image with the MSER detection: MSER detection: C:\fakepath\GDFXn.pngC:\fakepath\GDFXn.png

So i want to separate each object into an image, without any repetitions. Is anyone can help me?

Thank you! Rita Maia

This is my code so far:

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

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

vis = img.copy() mser = cv2.MSER_create()

cv2.MSER_create()

mser = cv2.MSER_create( _min_area = 5000, _max_area = 25000, _max_variation = 1.0) vis = img.copy() gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

cv2.COLOR_BGR2GRAY)

regions, _ = mser.detectRegions(gray)

mser.detectRegions(gray)

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

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])

img[y:y+h,x:x+w])