OpenCV Draw rectangle from center x,y
11,087
Considering that center=(x,y), then:
cv::rectangle( image,
cvPoint(x-w/2,y-h/2),
cvPoint(x+w/2,y+h/2),
CV_RGB(r,g,b), 1, 8
);
CvRect
stores the top-left point as reference. So:
CvRect myrect=cvRect(x-w/2,y-h/2,w,h);
Comments
-
Charles Osei over 1 year
I want to draw a rectangle using only a point to the center. So pretty much a rectangle around my center point. What is the easiest way of doing this?Thanks.
-
Carpetfizz about 7 yearsWhy
y+h/2/2
on the 3rd line? -
LovaBill about 7 yearsmaybe a typo? dont really remember. try it and fix it! :)
-
Carpetfizz about 7 yearsFixed! Bottom point should be center + height / 2 not center + height / 4