Correct threshold for HoughCircles() circle detection opencv c++

You can use following parameter values. These settings are able to detect the circles in your images.

cv::Mat img = cv::imread("75.bmp");
cv::Mat img_gray;
cv::cvtColor(img, img_gray, cv::COLOR_BGR2GRAY);
img_gray.convertTo(img_gray, CV_8UC1);
std::vector<cv::Vec3f> circles;
double minDist = 20;
double dp = 1;
double param1 = 200;
double param2 = 10;
int minRadius = 15;
int maxRadius = 25;
cv::HoughCircles(img_gray, circles, cv::HOUGH_GRADIENT, dp, minDist, param1, param2, minRadius, maxRadius);
if (circles.size() > 0) {
    for (size_t current_circle = 0; current_circle < circles.size(); ++current_circle) {
        cv::Point center(std::round(circles[current_circle][0]), std::round(circles[current_circle][1]));
        int radius = std::round(circles[current_circle][2]);
        cv::circle(img, center, radius, cv::Scalar(0, 255, 0), 1);
    }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top