c++ - 在图像/opencv/c++ 中获取检测到的圆的中心

标签 c++ opencv

我正在使用此代码获取图像中检测到的圆的中心坐标。

vector<Vec3f> circles;

    cv::HoughCircles( t, circles, CV_HOUGH_GRADIENT, 1, t.rows/8, 200,         100, 0, 0 );

       for( size_t i = 0; i < circles.size(); i++ ){
            Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
            cout << "center" << center << endl;
        int radius = cvRound(circles[i][2]);
            // circle center
            circle( t2, center, 3,  1 , -1, 8, 0 );        
             // circle outline
            circle( t2, center, radius,  1  , 3, 8, 0 );  
        }

        imshow( "circles", t2 );

我可以检测到圆圈,但没有得到中心点坐标的任何结果:(

提前致谢。

修改后:

我添加了这一行,但答案为零。

cout << "number of circles found: " << circles.size() << endl;

图像: 第一个是主圆,第二个是在应用高斯滤波器和 HoughCircles 函数之后:

enter image description here

最佳答案

如果我理解正确的话,你的代码会画出圆圈,但是

 cout << "center" << center << endl;

行没有给出正确的输出。

这是因为 cv::Point不支持通过 << 直接输出.

尝试使用:

 cout << "center" << center.x << ", " << center.y << endl;

如果问题是您找不到任何圆圈,请确保 min_radiusmax_radius被正确选择。尝试从宽范围的允许半径开始,然后尝试选择较小的范围,直到只得到您想要的圆。

这个值可以对检测率产生巨大的影响。

关于c++ - 在图像/opencv/c++ 中获取检测到的圆的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20043203/

相关文章:

c++ - 整数除法始终为零

c++ - MFC 调整大小对话框和子窗口绘制问题

c++ - boost 共享指针 : Simultaneous Read Access Across Multiple Threads

c++ - opencv中有DWT函数吗?

C++ 初始化列表与赋值

image-processing - 从模板识别对象

android - 使用 ORB 逐步进行对象检测

algorithm - 在 C++ 中使用 opencv 跟踪 AVI 视频中对象的最佳算法

c++ - 如果我使用UMat并在opencv中关闭GPU处理,速度会有所不同吗?

python - 使用 python-c-api 调用的 Cython 回调段错误