OpenCV MSER detection issue

asked 2018-05-22 05:34:45 -0500

maia07 gravatar image

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

berak gravatar image

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])
edit retag flag offensive close merge delete

Comments

without any repetitions.

that's unclear, please explain. does it detect several boxes in the same place or such ?

berak gravatar imageberak ( 2018-05-22 05:44:16 -0500 )edit
1

in the loop i save all the images and i have duplicate images like: 2 times "habitação" and 2 times "Climatização" etc

maia07 gravatar imagemaia07 ( 2018-05-22 05:49:27 -0500 )edit