Hello,
I have this image: C:\fakepath\botoes.PNG and i want to extract all the buttons and save them in different imagens. Untill now i have this code:
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))
cv2.imshow('img', vis)
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])
But it's not separate in the correct way. Does anybody know what i'm missing here in the code? Or what it's the best way to do it?
Thanks a lot.
Rita Maia