FastFeatureDetector does not detect sharp corners

asked 2018-08-08 07:22:58 -0600

irene gravatar image

I created a simple image of a square

image description

and ran FastFeatureDetector on it: I expected that Feature2d::detect would find the 4 corners. However, no feature points are detected.

I tested different types of images (gray, rgb) and various ways to draw a square (with Rect, rectangle, fillPoly, fillConvexPoly, ...).

Finally, we discovered that if the image is blurred, then the corner features are detected (drawn in blue over the blurred square):

image description

Here is the code:

        cv::Mat testImage(nSize, nSize, CV_8UC3, cv::Scalar(0, 0, 0));
        const int length = nSize / 3;
        cv::Mat square = cv::Mat(length, length, CV_8UC3, cv::Scalar(255, 255, 255));
        square.copyTo(testImage(cv::Rect(nSize / 3, nSize / 3, length, length)));

        cv::Ptr<cv::FeatureDetector> detector0 = cv::FastFeatureDetector::create();
        std::vector<cv::KeyPoint> keypoints0;
        detector0->detect(testImage, keypoints0);

        std::cout << "Number of features: " << keypoints0.size() << std::endl; // <-- 0

        cv::blur(testImage, testImage, cv::Size(3, 3));

        cv::Ptr<cv::FeatureDetector> detector = cv::FastFeatureDetector::create();
        std::vector<cv::KeyPoint> keypoints;
        detector->detect(testImage, keypoints);

        std::cout << "Number of features: " << keypoints.size() << std::endl; // <-- 4

Is this the expected behaviour? Testing other detectors on the same image, the corners of the square are found (original image without blurring).

Thanks!

edit retag flag offensive close merge delete