1 | initial version |
For each contour, you can obtain a boundingRectange, which you can then get the top left and bottom right x,y coordinates. Be mindful that the tl and br might actually represent tr and bl corners!
You can then extract the bounding rectangle center based on these coordinates.
Note that a bounding rectangle center may not be the centroid of the contour (indeed, it would rarely be exactly the same and might be significantly different, especially with concave contours that are crescent-like).
2 | raised the question of ground-plane as part of the use case |
For each contour, you can obtain a boundingRectange, which you can then get the top left and bottom right x,y coordinates. Be mindful that the tl and br might actually represent tr and bl corners!
You can then extract the bounding rectangle center based on these coordinates.
Note that a bounding rectangle center may not be the centroid of the contour (indeed, it would rarely be exactly the same and might be significantly different, especially with concave contours that are crescent-like).
If you mean x,y as in ground-plane, that is a more involved answer concerning finding a homography and performing a perspective transformation.