Ask Your Question

Revision history [back]

I can't paint the circle into image after using Hough transform :(

Hi everybody ! I used Hough transform to detect circle and then I will paint the circle into my input image ( tennis ball ) depend on those parameter that Hough issued ( center,radius ). Here is my code :

            Mat src1 = imread("banhtennis.jpg");
    Mat src2 = src1.clone();
    Mat gray,canny;

    cvtColor(src1,gray,CV_BGR2GRAY);
    Canny(gray,canny,20,30,3,false);
    vector<Vec3f> circles;
    HoughCircles(canny,circles,CV_HOUGH_GRADIENT,1,100,30,20,0,0);
    for(int i=0;i<circles.size();i++)
    {
        Point center(cvRound(circles[i][0]),cvRound(circles[i][1]));
        int radius = cvRound(circles[i][2]);
        circle(src2,center,radius,Scalar(0,0,255),2,8,0);
    }
            imshow("Anh sau khi tim thay duong tron",src2);

The result I received after running my program was many red circles that were painted on the input image but not the circle I need. I need the circle cover my ball in this image. Can everyone help me about this problem ? I will attach this image at here C:\fakepath\banhtennis.jpg Thanks very much ^^