Skip to content

SimpleBlobDetector regression #20649

@sergiud

Description

@sergiud
System information (version)
  • OpenCV => 4.5.3
  • Operating System / Platform => Arch Linux
  • Compiler => gcc 11.1
Detailed description

With OpenCV 4.5.3 one of my unit tests that uses SimpleBlobDetector started failing. Bisecting the commits identified #19859 as the PR that introduced the regression.

Without #19859 (OpenCV 4.5.3 with 7686093 reverted. Alternatively, OpenCV 4.5.2):
viz_before

With #19859 (tagged OpenCV 4.5.3):
viz_after
Note the identified keypoints outside of the blobs in the image center.

Steps to reproduce
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main()
{
    const unsigned cellWidth = 50;

    const int cellsX = 10;
    const int cellsY = 7;

    const uchar color = 0xff;

    cv::Mat1b image(cv::Size(cellWidth * cellsX, cellWidth * cellsY), uchar(0));

    // Create a mosaic pattern of big circles in the cell centers, and smaller
    // circles surrounded by four large circles (i.e., a small circle in the
    // bottom right edge of every cell).

    for (int x = 0; x < cellsX; ++x) {
        for (int y = 0; y < cellsY; ++y) {
            const cv::Point pt(x * cellWidth + cellWidth / 2,
                               y * cellWidth + cellWidth / 2);

            cv::circle(image, pt, cellWidth * 2 / 7,
                       CV_RGB(color, color, color), cv::FILLED, cv::LINE_AA);
        }
    }

    for (int x = 0; x < cellsX - 1; ++x) {
        for (int y = 0; y < cellsY - 1; ++y) {
            const cv::Point pt(x * cellWidth + cellWidth,
                               y * cellWidth + cellWidth);

            cv::circle(image, pt, cellWidth * 2 / 9,
                       CV_RGB(color, color, color), cv::FILLED, cv::LINE_AA);
        }
    }

    cv::SimpleBlobDetector::Params params{};
    params.filterByColor = true;
    params.filterByCircularity = true;
    params.filterByConvexity = false;
    params.thresholdStep = 127;
    params.blobColor = color;
    params.minThreshold = 128;
    params.maxThreshold = 255;
    params.minRepeatability = 1;

    cv::Ptr<cv::FeatureDetector> featureDetector(
        cv::SimpleBlobDetector::create(params));

    std::vector<cv::KeyPoint> kps;
    featureDetector->detect(image, kps);

    cv::Mat viz;
    cv::cvtColor(image, viz, cv::COLOR_GRAY2BGR);

    for (const cv::KeyPoint& kp : kps) {
        cv::circle(viz, kp.pt, 2, CV_RGB(255, 0, 0), cv::FILLED);
    }

    cv::imwrite("viz.png", viz);
    cv::imshow("foo", viz);
    cv::waitKey();
}
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions