繁体   English   中英

使用opencv和c ++在检测到的圆周围绘制一个矩形

[英]draw a rectangle around a detected circle using opencv and c++

假设我有一个使用此圆函数检测到的坐标为(center.x和center.y)的圆:

GaussianBlur( dis, dis, Size(3, 3), 2, 2 );

vector<Vec3f> circles;

HoughCircles( dis, circles, CV_HOUGH_GRADIENT, 1, dis.rows/8, 200, 100);

for( size_t i = 0; i < circles.size(); i++ ){

      Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
      cout << "center" << center.x << ", " << center.y << endl;
       // coordinates of center points
      V.push_back(std::make_pair(center.x,center.y));     
       int radius = cvRound(circles[i][2]);
       // circle center
      circle( dis, center, 3, 1, -1, 8, 0 );
       // circle outline
      circle( dis, center, radius, 1, 3, 8, 0 );
  }

如何围绕此圆绘制一个矩形,圆的中心位于矩形的中间,中心与每一边之间的距离为“半径+ x”?

我是图像处理方面的新手,对不起这个简单的问题。 我将不胜感激任何帮助..

......编辑代码..................

cv::rectangle( diatence, cvPoint((center.x)-(radius+10),(center.y)-(radius+10)), cvPoint((center.x)+(radius+10),(center.y)+(radius+10)), 1, 1, 8 );

假设中心位于x,y,则需要绘制一个具有以下规格的矩形:

top left corner : x-(radius+a),y-(radius+a)
bottom right corner : x+(radius+a),y+(radius+a)

其中a是要添加到半径的任意值。

更一般地:给定中心点x,y和已知矩形的大小LxH,您可以通过将左上角的点指定为x-(L/2),y-(H/2)来绘制矩形-右点为x+(L/2),y+(H/2)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM