gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:04:32 26 4
gpt4 key购买 nike

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

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com