Markers on an image detection

asked 2015-07-20 02:29:12 -0600

image description

Hello. I am recieving a stream of images from a simulation program, called V-REP. The idea is that i have to detect only the red circles and determining their diameter, or something like this, to know the distance between my vision sensor and the circle. I managed to get the following result, so my algorithm sees only the red circles, ignoring the green one and anything else.

But I kind of got stuck, and I would need some help. Can you give me an idea?

Mat ocvimage;
    ocvimage=cvCreateImage(cvSize(res[0], res[1]), 8, 3);
    for (unsigned int i=0;i<res[1];i++){
            for (unsigned int j=0;j<res[0];j++){
                int r,g,b;
                r=cvRound(255*imageBuffer[3*((res[1]-i)*res[0]+j)+0]);
                g=cvRound(255*imageBuffer[3*((res[1]-i)*res[0]+j)+1]);
                b=cvRound(255*imageBuffer[3*((res[1]-i)*res[0]+j)+2]);

                ocvimage.at<Vec3b>(i,j)[0] = (uchar)b;
                ocvimage.at<Vec3b>(i,j)[1] = (uchar)g;
                ocvimage.at<Vec3b>(i,j)[2] = (uchar)r;
            }
        }

    //Detecting red circles and marking them
    Mat orig_image = ocvimage.clone();

    medianBlur(ocvimage, ocvimage, 3);

    Mat hsv_image;
    cv::cvtColor(ocvimage, hsv_image, cv::COLOR_BGR2HSV);

    cv::Mat lower_red_hue_range;
    cv::Mat upper_red_hue_range;
    cv::inRange(hsv_image, cv::Scalar(0, 100, 100), cv::Scalar(10, 255, 255), lower_red_hue_range);
    cv::inRange(hsv_image, cv::Scalar(160, 100, 100), cv::Scalar(179, 255, 255), upper_red_hue_range);


    cv::Mat red_hue_image;
    cv::addWeighted(lower_red_hue_range, 1.0, upper_red_hue_range, 1.0, 0.0, red_hue_image);

    cv::GaussianBlur(red_hue_image, red_hue_image, cv::Size(9, 9), 2, 2);

Thats my algorithm's main part, so far.
I had some heap memory troubles with HoughCircles, which I could not get around it, so I wanted to ask you guys for another approach.

Thanks!

edit retag flag offensive close merge delete