gpt4 book ai didi

c++ - opencv检测到多个小圆圈,但没有检测到更大的圆圈

转载 作者:行者123 更新时间:2023-11-27 23:58:07 25 4
gpt4 key购买 nike

我是 OpenCV 的新手,我试图只检测一分钱图像,但我得到了一堆小圆圈。谁能告诉我我做错了什么?

代码来自这里:https://github.com/opencv/opencv/blob/master/samples/cpp/houghcircles.cpp

我唯一改变的是使最小圆半径为 400,最大圆为 0。因为我知道图像将是 600x480,所以便士圆必须至少为 400。

#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"

#include <iostream>

using namespace cv;
using namespace std;

static void help()
{
cout << "\nThis program demonstrates circle finding with the Hough transform.\n"
"Usage:\n"
"./houghcircles <image_name>, Default is ../data/board.jpg\n" << endl;
}

int main(int argc, char** argv)
{
cv::CommandLineParser parser(argc, argv,
"{help h ||}{@image|../data/board.jpg|}"
);
if (parser.has("help"))
{
help();
return 0;
}
//![load]
string filename = parser.get<string>("@image");
Mat img = imread(filename, IMREAD_COLOR);
if(img.empty())
{
help();
cout << "can not open " << filename << endl;
return -1;
}
//![load]

//![convert_to_gray]
Mat gray;
cvtColor(img, gray, COLOR_BGR2GRAY);
//![convert_to_gray]

//![reduce_noise]
medianBlur(gray, gray, 5);
//![reduce_noise]

//![houghcircles]
vector<Vec3f> circles;
HoughCircles(gray, circles, HOUGH_GRADIENT, 1,
gray.rows/16, // change this value to detect circles with different distances to each other
100, 30, 400,0 // change the last two parameters
// (min_radius & max_radius) to detect larger circles
);
//![houghcircles]

//![draw]
for( size_t i = 0; i < circles.size(); i++ )
{
Vec3i c = circles[i];
circle( img, Point(c[0], c[1]), c[2], Scalar(0,0,255), 3, LINE_AA);
circle( img, Point(c[0], c[1]), 2, Scalar(0,255,0), 3, LINE_AA);
}
//![draw]

//![display]
imshow("detected circles", img);
waitKey();
//![display]

return 0;
}

enter image description here

enter image description here

最佳答案

您混淆了半径和直径。如果图片只有 600x480,则最小半径不能为 400。将您的 min_radius 设置为 200。

关于c++ - opencv检测到多个小圆圈,但没有检测到更大的圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41092023/

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