# How to find a point in two bounding rectangle

how do you find the coordinates of the center of each rectangle

vector<vector> contours;
vector hierarchy;

``````	findContours(canny, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);

vector<Rect> bounders;

for (int i = 0; i < contours.size(); i++) {
int area = contourArea(contours[i]);
if (area < max_area && area > min_area) {
bounders.push_back(boundingRect(contours[i]));
}
}

Mat imgBox = imgRgb.clone();
for (int i = 0; i < bounders.size(); i++) {

Rect r1 = bounders[i];

rectangle(imgBox, bounders[i], Scalar(0, 0, 255), 2);
circle(imgBox, Point(bounders[i].x + bounders[i].width / 2, bounders[i].y + bounders[i].height / 2), 10, Scalar(0, 0, 255), 2);

}``````

Your circle method call there shows you roughly how to calculate the center (x,y) coordinates of your rectangle.

You assign r1 to the current array index of your bounded rectangles.

`r1.x + r1.width/2, r1.y + r1.height/2` is giving you (X,Y) coordinates of the center of the rectangle.

To find the center of two rectangles, you just need to do that on the other rectangle as well.

If I’m reading it correctly, this should be the x,y coordinates of the rectangle I.
Edit: sniped.