gpt4 book ai didi

opencv - 使用opencv HoughCircles检测实心白色圆圈

转载 作者:太空宇宙 更新时间:2023-11-03 21:23:01 30 4
gpt4 key购买 nike

我正在尝试使用 opencv 检测实心圆。 opencv 文档中的示例代码似乎无法检测到纯白色。我将如何修改该代码以适用于实心白色圆圈?您能解释一下为什么它不适用于实心白色圆圈吗?

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace cv;

/** @function main */
int main(int argc, char** argv)
{
Mat src, src_gray;

/// Read the image
src = imread( argv[1], 1 );

if( !src.data )
{ return -1; }

/// Convert it to gray
cvtColor( src, src_gray, CV_BGR2GRAY );

/// Reduce the noise so we avoid false circle detection
GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );

vector<Vec3f> circles;

/// Apply the Hough Transform to find the circles
HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );

/// Draw the circles detected
for( size_t i = 0; i < circles.size(); i++ )
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
// circle center
circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
// circle outline
circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
}

/// Show your results
namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
imshow( "Hough Circle Transform Demo", src );

waitKey(0);
return 0;
}

我会发布图片,但我还没有足够的堆栈溢出街头信誉。对不起!

最佳答案

你应该先提取边缘。这就是Hough Transform检测。添加cvCanny在 HoughCircles 之前进行转换。

关于opencv - 使用opencv HoughCircles检测实心白色圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7036103/

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