0

如何估计我检测到的不规则圆的半径?我习惯于findContours()找到圆圈的位置并习惯于moments()找到质心。我现在只需要圆的半径,这样我就可以估计它的体积。

为了找到轮廓,我使用了以下代码:

findContours(Closed_Image, Contours, Hierarchy, 
             CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0,0) );

为了找到质心,我使用了以下代码:

vector<Moments> mu(Contours.size() );
b = 0;
for(b = 0; b < Contours.size(); b++)
{
    mu[b] = moments(Contours[b], true);
}

vector<Point2f> mc(Contours.size() );
c = 0;
for(c = 0; c < Contours.size(); c++)
{
    mc[c] = Point2f(mu[c].m10/mu[c].m00, mu[c].m01/mu[c].m00);
    cout << "Contours Centre = " << mc[c] << endl;
}

我猜我需要使用存储在其中的轮廓点,Contours但形状不是一个完美的圆形,因此轮廓中每个点与其质心之间的距离会有所不同。这只是平均质心和轮廓中每个点之间的距离(平均距离=半径)的问题吗?如果是这样,我该如何实际实现它(我不确定如何访问 中的数据vector<vector<Point> > Contours;)。否则,我将如何实现对半径的估计?

(单击此处查看我正在使用的图像)

质心如下:[424.081, 13.4634], [291.159, 10.4545], [157.833, 10.4286], [24.5198, 8.09127]

4

0 回答 0