Ask Your Question

Revision history [back]

    Rect r(100,100,60,80);
    Point center_of_rect = (r.br() + r.tl())*0.5;

gives center of rect

#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

using namespace cv;

int main()
{
    Mat image(400,400,CV_8UC3,Scalar(0,0,0));
    Rect r(100,100,60,80);
    rectangle(image,r,Scalar(0,255,255),2);
    Point center_of_rect = (r.br() + r.tl())*0.5;
    circle(image,center_of_rect,3,Scalar(0,0,255));

    imshow("image",image);
    waitKey();

    return 0;
}