检测到随机圆圈

发布于 2024-12-07 17:28:20 字数 1117 浏览 0 评论 0原文

我正在尝试检测圆圈,但检测到的圆圈根本不存在。我的代码如下。任何人都知道如何修改 DetectCircle() 方法以使检测更准确,请谢谢

void detectCircle( IplImage * img )
{
    int edge_thresh = 1;
    IplImage *gray = cvCreateImage( cvSize(img->width,img->height), 8, 1);
    IplImage *edge = cvCreateImage( cvSize(img->width,img->height), 8, 1);

    cvCvtColor(img, gray, CV_BGR2GRAY);

    gray->origin = 1;

    // color threshold
    cvThreshold(gray,gray,100,255,CV_THRESH_BINARY);    

    // smooths out image
    cvSmooth(gray, gray, CV_GAUSSIAN, 11, 11);

    // get edges
    cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 5); 

    // detects circle
    CvSeq* circle =  cvHoughCircles(edge, cstorage, CV_HOUGH_GRADIENT, 1,
        edge->height/50, 5, 35);

    // draws circle and its centerpoint
    float* p = (float*)cvGetSeqElem( circle, 0 );
    if( p==null ){ return;}

    cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), 3, CV_RGB(255,0,0), -1, 8, 0 );
    cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(200,0,0), 1, 8, 0 );

    cvShowImage ("Snooker", img );
}

I'm trying to detect circles but I am detecting circles that aren't even there. My code is below. Anyone know how to modify the DetectCircle() method to make the detection more accurate , please and thanks

void detectCircle( IplImage * img )
{
    int edge_thresh = 1;
    IplImage *gray = cvCreateImage( cvSize(img->width,img->height), 8, 1);
    IplImage *edge = cvCreateImage( cvSize(img->width,img->height), 8, 1);

    cvCvtColor(img, gray, CV_BGR2GRAY);

    gray->origin = 1;

    // color threshold
    cvThreshold(gray,gray,100,255,CV_THRESH_BINARY);    

    // smooths out image
    cvSmooth(gray, gray, CV_GAUSSIAN, 11, 11);

    // get edges
    cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 5); 

    // detects circle
    CvSeq* circle =  cvHoughCircles(edge, cstorage, CV_HOUGH_GRADIENT, 1,
        edge->height/50, 5, 35);

    // draws circle and its centerpoint
    float* p = (float*)cvGetSeqElem( circle, 0 );
    if( p==null ){ return;}

    cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), 3, CV_RGB(255,0,0), -1, 8, 0 );
    cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(200,0,0), 1, 8, 0 );

    cvShowImage ("Snooker", img );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风蛊 2024-12-14 17:28:20

cvHoughCircles 检测对我们来说不明显的圆圈。如果您知道斯诺克球的像素大小,您可以根据球的半径对其进行过滤。尝试在 cvHoughCircles 函数中设置 min_radius 和 max_radius 参数。

顺便说一句,一旦获得圆圈,您可以根据颜色对其进行过滤。如果圆圈主要是一种颜色,则它很可能是一个球,如果不是,则可能是误报。

编辑:“圆圈的颜色”是指圆圈边界内的像素

cvHoughCircles detects circles that arent obvious to us. If you know the pixel size of snooker balls you can filter them based on their radius. Try setting the min_radius and max_radius parameters in your cvHoughCircles function.

On a side note, once you get the circles, you can filter them based on color. If the circle is mostly one color, it has a good chance of being a ball, if it doenst its probably a false positive.

edit: by "circle's color" i mean the pixels inside the circle boundary

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文