Ask Your Question

Revision history [back]

Multiple circles with a single call to cv::circle function

Hello everyone.

I'm new with OpenCV library, and I would like to use it to detect circle in a video stream captured from an iPad back camera. I figured out how to do it and with OpenCV, it can be done in less than 10 lines of code. But it doesn't work for me, and I think I missed something because of some weird behaviours I obtain.

Here is a very simple code that doesn't work:

void proccessImage(std::vector<unsigned char>& imageData, int width, int height)
{
    // Create cv::Mat from std::vector<unsigned char>
    Mat src(width, height, CV_8UC4, const_cast<unsigned char*>(imageData.data()));
    Mat src_gray;
    Mat final;

    // Convert the original image from BGRA to gray
    cvtColor(src, src_gray, CV_BGRA2GRAY);

    // Draw a circle at position (300, 200) with a radius of 30
    cv::Point center(300, 200);
    circle(src_gray, center, 30.f, Scalar(0,0,255, 255), 3, 8, 0);

    // Convert the gray image to RGBA
    cvtColor(src_gray, final, CV_GRAY2RGBA);

    // Reform the std::vector from cv::Mat data
    std::vector<unsigned char> array;
    array.assign((unsigned char*)final.datastart, (unsigned char*)final.dataend);

    // Send final image data to GPU and draw it
}

For me, this should convert the image in gray and draw a simple circle at the specified position. But instead of that, I get this:

image description

[the data from the iPad's back camera is correct and is gray, but the circle is drawn multiple times with weird stripes]

Do you know what happened?