python-polylabel icon indicating copy to clipboard operation
python-polylabel copied to clipboard

Point always on contour edge

Open simon-hauser opened this issue 4 years ago • 3 comments

Hi,

Thank you for implementing the algorithm in python. I'm trying to use it on contours from a binary mask. The contours are returned from cv2.findContours, and I would like to compute the visual center for every contour. However, cx, cy = polylabel(cnt.tolist()) always returns a point that is on the edge of the contour, not in the middle (the .tolist() might not be required). Would you have any hint if I'm using polylabel correctly? Many thanks.

simon-hauser avatar Nov 16 '21 10:11 simon-hauser

Hello,

Sorry for the late response.

You might try to play with precision parameter in the polylabel cal.

Twista avatar Dec 14 '21 10:12 Twista

I have the same problem. It works fine for sample polygons, but not for masks I generate with CVs findContours function.

mkals avatar Oct 20 '22 19:10 mkals

I solved my issue - findCountours returns a set of coordinates in the form [[[1,2]],[[3,4]],...]. Polylabel needs the list to be formatted as [[[1,2],[3,4],...]]. Hope this helps others that may stumble on this. @Twista - thanks for a great package!

mkals avatar Oct 20 '22 19:10 mkals