OpenCV Draw rectangle from center x,y

怎甘沉沦 提交于 2021-02-07 09:27:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!