繁体   English   中英

OPENCV ::查找两个同心圆之间的所有点

[英]OPENCV :: Find all the points between two concentric circles

我有两个同心圆a和b,我从图像中检测到这些圆,我知道它们的半径。 我想要的是两个同心圆之间的点,以便可以从这些点中提取RGB值。 任何帮助将是有益的。

两个同心圆之间的点的索引( x, y )(中心( x_0, y_0 ),半径r_0, r_1r_1 > r_0 )必须满足以下条件:

(x-x_0) * (x-x_0) + (y-y_0) * (y-y_0) >= r_0 * r_0
(x-x_0) * (x-x_0) + (y-y_0) * (y-y_0) <= r_1 * r_1

因此,当遍历图像的所有点时,您可以确定要处理的点:

for (int x=0; x<img.rows; x++)
{
   for (int y=0; y<img.cols; y++)
   {
       double dd = (x-x_0) * (x-x_0) + (y-y_0) * (y-y_0);
       if (dd < r_0 * r_0 || dd > r_1 * r_1)
         continue;

       // Do what you have to do with the points between the two circles
   }
}

伪代码:

Make a Mat of the same size as your source image. 
Draw the two filled circles with the built-in OpenCV circle drawing routine. 
  (large circle in white, then the small in black) 
Use that as a mask, that you multiply on your source image. 
(Depending on which pixels you wish to keep, the mask may have to be inverted.)

如果您需要访问所有像素并以某种方式收集它们的颜色值,并且您只想访问有问题的像素,因为速度至关重要,那么我建议您研究一下Bresenham编写中点圆算法 您可以对此进行专门化,以便每像素线仅获得2或4个点,并遍历每条线的成对点。 应该是O(n),其中n是以像素为单位的高度(直径,即最大半径),因此您将看到o(m),m是两个像素之间的像素数,而不是n ^ 2。 如果大图像和半径彼此靠近,那将很重要。

在此处输入图片说明

暂无
暂无

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

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