开发者

Random circles being detected

开发者 https://www.devze.com 2023-04-10 04:19 出处:网络
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

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 );
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号