从图像或网络摄像头框架中的其他圆圈中检测目标圆圈

时间:2016-01-08 00:37:12

标签: c++ opencv

我正在尝试检测此圈circle1

在包含其他几个圈circles的图片中。  你会怎么做这样的事情?我尝试将两种颜色范围结合起来,但这不起作用。

这是我目前的代码:

    // Threshold for yellow colour on the Drop-off point
    int bLowH = 25;
    int bHighH = 79;
    int bLowS = 0;
    int bHighS = 121;
    int bLowV = 87;
    int bHighV = 196;

    // Threshold values for red colour on the Drop-off point
    int gLowH = 148;
    int gHighH = 180;
    int gLowS = 54;
    int gHighS = 255;
    int gLowV = 96;
    int gHighV = 247;

    Mat imgHSV;
    Mat yellowRange;
    Mat redRange;


    cvtColor(frame, imgHSV, COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV
    //Threshold the images.. Only Keep The threshold values for the dropoff point
    inRange(imgHSV, Scalar(bLowH, bLowS, bLowV), Scalar(bHighH, bHighS, bHighV), yellowRange); 
    inRange(imgHSV, Scalar(gLowH, gLowS, gLowV), Scalar(gHighH, gHighS, gHighV), redRange);


    // combine both images and slightly blur...
    Mat dropoff_image;
    addWeighted(yellowRange, 1.0, redRange, 1.0, 0.0, dropoff_image);
    GaussianBlur(dropoff_image, dropoff_image, Size(9, 9), 2, 2);

    // Hough Transform to detect circle
    vector<Vec3f> dropoff;
    HoughCircles(dropoff_image, dropoff, CV_HOUGH_GRADIENT, 1, dropoff_image.rows / 8, 100, 20, 0, 0);

    if (dropoff.size() == 0)
    {
        cout << "No dropoff circle found" << endl;
        exit(-1);
    }

    for (size_t current_circle = 0; current_circle < dropoff.size(); ++current_circle)
    {
        cout << "circle found" << endl;
        Point center(round(dropoff[current_circle][0]), round(dropoff[current_circle][1]));
        int radius = round(dropoff[current_circle][2]);

        circle(frame, center, radius, Scalar(0, 255, 0), 5);
        imshow("Gaussian", dropoff_image);
    }

0 个答案:

没有答案