Ask Your Question

Revision history [back]

Inevitably, we need to consider the characteristics of "circle" and try SimpleBlobDetector to implement it. The changes also include canceling the parameters of the basic morphological transformation, or directly canceling the morphological change.

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"

void main()
{
    const cv::Mat in = cv::imread("e:/template/findcircle.jpg");
    cv::Mat src;
    cv::dilate(in, src, cv::Mat());
    cv::erode(src, src, cv::Mat());

    cv::Mat hsv;
    cv::cvtColor(src, hsv, cv::COLOR_BGR2HSV);

    std::vector<cv::Mat> split_s;
    cv::split(hsv, split_s);
    split_s[1] = split_s[1] > 70;

    SimpleBlobDetector::Params params;
    params.filterByColor = false;
    params.minThreshold = 120;
    vector<KeyPoint> keypoints;
    Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
    detector->detect(split_s[1], keypoints);
    drawKeypoints(in, keypoints, in, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    cv::imshow("result", in);
}

Inevitably, we need to consider the characteristics of "circle" and try SimpleBlobDetector to implement it. The changes also include canceling the parameters of the basic morphological transformation, or directly canceling the morphological change.

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <opencv2/features2d.hpp>

void main()
{
    const cv::Mat in = cv::imread("e:/template/findcircle.jpg");
cv::imread("15996646131571621.jpg");
    cv::Mat src;
    cv::dilate(in, src, cv::Mat());
    cv::erode(src, src, cv::Mat());

    cv::Mat hsv;
    cv::cvtColor(src, hsv, cv::COLOR_BGR2HSV);

    std::vector<cv::Mat> split_s;
    cv::split(hsv, split_s);
    split_s[1] = split_s[1] > 70;

    SimpleBlobDetector::Params cv::SimpleBlobDetector::Params params;
    params.filterByColor = false;
    params.minThreshold = 120;
    vector<KeyPoint> std::vector<cv::KeyPoint> keypoints;
    Ptr<SimpleBlobDetector> cv::Ptr<cv::SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
cv::SimpleBlobDetector::create(params);
    detector->detect(split_s[1], keypoints);
    drawKeypoints(in, cv::drawKeypoints(in, keypoints, in, Scalar(0, cv::Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    cv::imshow("result", in);
    cv::waitKey();
}