How to connect center of detected objects/contours to form a polygon?
Like for example, I've detected all the objects I want to detect. I already find each of its centers. Now, I want to connect all of its center to form closed polygon. Here are the coordinates of the center of the objects: [(412, 429), (249, 418), (400, 193), (561, 181), (541, 57), (256, 50)] I used convexHull and drawContours, it works fine with shapes like squares and rectangles but the problem is it didn't work out like in the sample image. It just connect all the outer objects. Btw, I used python for programming language.
Here is my sample code snippet:
centers = [(412, 429), (249, 418), (400, 193), (561, 181), (541, 57), (256, 50)]
pts = cv2.convexHull(np.array(centers))
cv2.drawContours(img, [pts], 0, (0,0,0), 3)
your points are NOT convex