Circles are blinking on window

asked 2018-05-29 02:39:59 -0500

prabzz gravatar image

updated 2018-05-29 05:37:24 -0500

Hi

I am finding circles on image and drawing the circles on image. But circles are always blinking on window. Here it is my c++ code which i am using

-(Mat) findCircles:(Mat&)image {
Mat mask, res, hsv_image;
medianBlur(image, image, 5);
cvtColor(image, image, CV_BGR2HSV);
inRange(hsv_image, Scalar(110,50,50), Scalar(130,255,255), mask);
// Combine the above two images
cv::Mat blue_hue_image;
cv::addWeighted(mask, 1.0, mask, 1.0, 0.0, blue_hue_image);

GaussianBlur(blue_hue_image, blue_hue_image, cv::Size(9,9), 2,2);
vector<Vec3f> circles;
HoughCircles(image, circles, HOUGH_GRADIENT, 1, image.rows/8, 100, 30, 5, 10 // change the last two parameters
             // (min_radius & max_radius) to detect larger circles
             );

// Cluster circles near each other
vector<int> labels;
int n_labels = partition(circles, labels, CirclesOnSameLine(1.1f));

vector<Scalar> colors;
for (int i = 0; i < n_labels; ++i)
{
    Scalar color(rand() & 255, rand() & 255, rand() & 255);
    colors.push_back(color);
}

//    Mat3b adjacent = image.clone();
for (size_t i = 0; i < circles.size(); i++)
{
    cv::Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
    int radius = cvRound(circles[i][2]);
    // draw the circle outline
    circle(image, center, radius, colors[labels[i]], 3, 8, 0);
}

// Remove small clusters
vector<int> count(labels.size(), 0);
for (size_t i = 0; i < labels.size(); ++i)
{
    count[labels[i]]++;
}

//    Mat3b big_clusters = image.clone();
for (size_t i = 0; i < circles.size(); i++)
{
    if (count[labels[i]] < 4) continue;
    cv::Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
    int radius = cvRound(circles[i][2]);
    // draw the circle outline
    circle(image, center, radius, Scalar(0, 0, 255), 3, 8, 0);
}
cout<<"Total circle : "<<circles.size() <<endl;
return image;
}
edit retag flag offensive close merge delete

Comments

explain "blinking" , please.

maybe the random coloring is not that useful ?

berak gravatar imageberak ( 2018-05-29 02:51:04 -0500 )edit

Its means finding circle on image and drawing outline on circle and displaying image. But my circle outline is blinking but it should not blink and it must be show constant circle on that image.

prabzz gravatar imageprabzz ( 2018-05-29 05:39:38 -0500 )edit

an image can't "blink". (a sequence of images,maybe.)

berak gravatar imageberak ( 2018-05-29 06:13:35 -0500 )edit