OpenCV 从中心 x,y 绘制矩形 [英] OpenCV Draw rectangle from center x,y

查看:62
本文介绍了OpenCV 从中心 x,y 绘制矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想只使用一个指向中心的点来绘制一个矩形.所以几乎是围绕我的中心点的矩形.最简单的方法是什么?谢谢.

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.

推荐答案

考虑到 center=(x,y),则:

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 存储左上角的点作为参考.所以:

CvRect stores the top-left point as reference. So:

CvRect myrect=cvRect(x-w/2,y-h/2,w,h);

这篇关于OpenCV 从中心 x,y 绘制矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆