问题
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.
回答1:
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);
来源:https://stackoverflow.com/questions/17785602/opencv-draw-rectangle-from-center-x-y