Ask Your Question
-5

Finding center of Rect

asked 2016-08-24 18:39:17 -0500

Quzal gravatar image

How can I find the center of Rect ?

edit retag flag offensive close merge delete

Comments

5

seriously ?

berak gravatar imageberak ( 2016-08-24 19:46:59 -0500 )edit
1

haha I guess he is ^_^

StevenPuttemans gravatar imageStevenPuttemans ( 2016-08-25 06:35:53 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
6

answered 2016-08-24 18:53:04 -0500

    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;
}
edit flag offensive delete link more

Comments

How do this in java ?

EdoTwentySix gravatar imageEdoTwentySix ( 2018-04-06 05:03:50 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-08-24 18:39:17 -0500

Seen: 8,907 times

Last updated: Aug 24 '16