Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Circles are blinking on window

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;

}

Circles are blinking on window

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;

}

Circles are blinking on window

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;

}

Circles are blinking on window

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;
}

}