Attention! This forum will be made read-only by Dec-20. Please migrate to https://forum.opencv.org. Most of existing active users should've received invitation by e-mail.
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Opencv multiple circle detection in a image

Hey there, I writing a code for colony counter (Spots detection on a plate), This is the code i'm using as of now.

const cv::Mat in = load_image;   // Load image from a folder
cv::Mat tmp_mat, red_mat, blur_mat, gray_mat;
std::vector<cv::Mat> split_s;

cv::cvtColor(in, tmp_mat, cv::COLOR_BGR2HSV);
cv::split(tmp_mat, split_s);

cv::Mat mas_img, out_img;

for(int i = 0; i < load_image.rows; i++)
{
    for(int j = 0; j < load_image.cols; j++)
    {
        if((int)split_s[1].at<uchar>(i,j) >=
  70)
        {
            split_s[1].at<uchar>(i,j) = 250;
        }
        else {
            split_s[1].at<uchar>(i,j) = 0;
        }
      }
  }
cv::imshow("After", split_s[1]); 
cv::GaussianBlur(split_s[1], split_s[1], cv::Size(3,3), 0, 0); 
cv::imshow("Blur", split_s[1]);

std::vector<cv::Vec3f> circles;
cv::HoughCircles(split_s[1], circles, cv::HOUGH_GRADIENT, 1,
distances to each other
             200, 20, 1, 50 
);
for( size_t i = 0; i < circles.size(); i++ )
{
    cv::Vec3i c = circles[i];
    cv::Point center = cv::Point(c[0], c[1]);
    int radius = c[2];
    cv::circle( load_image, center, radius, cv::Scalar(255,0,255),
 2, cv::LINE_AA);
 }
 cv::imshow("result", load_image);

The Output of cv::imshow("Blur", split_s[1]) is as follows:

image description**

but the problem is after HoughCircles Detection not every circle is detected. How to detected each and every circle in the image

Opencv multiple circle detection in a image

Hey there, I writing a code for colony counter (Spots detection on a plate), This is the code i'm using as of now.

const cv::Mat in = load_image;   // Load image from a folder
cv::Mat tmp_mat, red_mat, blur_mat, gray_mat;
std::vector<cv::Mat> split_s;

cv::cvtColor(in, tmp_mat, cv::COLOR_BGR2HSV);
cv::split(tmp_mat, split_s);

cv::Mat mas_img, out_img;

for(int i = 0; i < load_image.rows; i++)
{
    for(int j = 0; j < load_image.cols; j++)
    {
        if((int)split_s[1].at<uchar>(i,j) >=
  70)
        {
            split_s[1].at<uchar>(i,j) = 250;
        }
        else {
            split_s[1].at<uchar>(i,j) = 0;
        }
      }
  }
cv::imshow("After", split_s[1]); 
cv::GaussianBlur(split_s[1], split_s[1], cv::Size(3,3), 0, 0); 
cv::imshow("Blur", split_s[1]);

std::vector<cv::Vec3f> circles;
cv::HoughCircles(split_s[1], circles, cv::HOUGH_GRADIENT, 1,
distances to each other
             200, 20, 1, 50 
);
for( size_t i = 0; i < circles.size(); i++ )
{
    cv::Vec3i c = circles[i];
    cv::Point center = cv::Point(c[0], c[1]);
    int radius = c[2];
    cv::circle( load_image, center, radius, cv::Scalar(255,0,255),
 2, cv::LINE_AA);
 }
 cv::imshow("result", load_image);

The Output of cv::imshow("Blur", split_s[1]) is as follows:

image description**

but the problem is after HoughCircles Detection not every circle is detected. How to detected each and every circle in the image

Edit 1: Original Image:- image description

Opencv multiple circle detection in a image

Hey there, I writing a code for colony counter (Spots detection on a plate), This is the code i'm using as of now.

const cv::Mat in = load_image;   // Load image from a folder
cv::Mat tmp_mat, red_mat, blur_mat, gray_mat;
std::vector<cv::Mat> split_s;

cv::cvtColor(in, tmp_mat, cv::COLOR_BGR2HSV);
cv::split(tmp_mat, split_s);

cv::Mat mas_img, out_img;

for(int i = 0; i < load_image.rows; i++)
{
    for(int j = 0; j < load_image.cols; j++)
    {
        if((int)split_s[1].at<uchar>(i,j) >=
  70)
        {
            split_s[1].at<uchar>(i,j) = 250;
        }
        else {
            split_s[1].at<uchar>(i,j) = 0;
        }
      }
  }
cv::imshow("After", split_s[1]); 
cv::GaussianBlur(split_s[1], split_s[1], cv::Size(3,3), 0, 0); 
cv::imshow("Blur", split_s[1]);

std::vector<cv::Vec3f> circles;
cv::HoughCircles(split_s[1], circles, cv::HOUGH_GRADIENT, 1,
distances to each other
             200, 20, 1, 50 
);
for( size_t i = 0; i < circles.size(); i++ )
{
    cv::Vec3i c = circles[i];
    cv::Point center = cv::Point(c[0], c[1]);
    int radius = c[2];
    cv::circle( load_image, center, radius, cv::Scalar(255,0,255),
 2, cv::LINE_AA);
 }
 cv::imshow("result", load_image);

The Output of cv::imshow("Blur", split_s[1]) is as follows:

image description**

but the problem is after HoughCircles Detection not every circle is detected. How to detected each and every circle in the image

Edit 1: Original Image:- image description

Opencv multiple circle detection in a image

Hey there, I writing a code for colony counter (Spots detection on a plate), This is the code i'm using as of now.

const cv::Mat in = load_image;   // Load image from a folder
cv::Mat tmp_mat, red_mat, blur_mat, gray_mat;
std::vector<cv::Mat> split_s;

cv::cvtColor(in, tmp_mat, cv::COLOR_BGR2HSV);
cv::split(tmp_mat, split_s);

cv::Mat mas_img, out_img;

for(int i = 0; i < load_image.rows; i++)
{
    for(int j = 0; j < load_image.cols; j++)
    {
        if((int)split_s[1].at<uchar>(i,j) >=
  70)
        {
            split_s[1].at<uchar>(i,j) = 250;
        }
        else {
            split_s[1].at<uchar>(i,j) = 0;
        }
      }
  }
cv::imshow("After", split_s[1]); 
cv::GaussianBlur(split_s[1], split_s[1], cv::Size(3,3), 0, 0); 
cv::imshow("Blur", split_s[1]);

std::vector<cv::Vec3f> circles;
cv::HoughCircles(split_s[1], circles, cv::HOUGH_GRADIENT, 1,
distances to each other
             200, 20, 1, 50 
);
for( size_t i = 0; i < circles.size(); i++ )
{
    cv::Vec3i c = circles[i];
    cv::Point center = cv::Point(c[0], c[1]);
    int radius = c[2];
    cv::circle( load_image, center, radius, cv::Scalar(255,0,255),
 2, cv::LINE_AA);
 }
 cv::imshow("result", load_image);

The Output of cv::imshow("Blur", split_s[1]) is as follows:

image description**

but the problem is after HoughCircles Detection not every circle is detected. How to detected each and every circle in the image

Edit 1: Original Image:- image description

Edit 2: Result Image:- image description