Repository: opencv/opencv
File: modules/features2d/test/test_orb.cpp (C++)

Code before:
{
    applyTestTag(
        CV_TEST_TAG_LONG,
        CV_TEST_TAG_DEBUG_VERYLONG,
        CV_TEST_TAG_MEMORY_6GB
    );

    const int width = 25000;
    const int height = 25000;
    Mat img(Size(width, height), CV_8UC1, Scalar::all(0));

    const int border = 23, num_lines = 23;
    for (int i = 0; i < num_lines; i++)
    {
        cv::Point2i point1(border + i * 100, border + i * 100);
        cv::Point2i point2(width - border - i * 100, height - border * i * 100);
        cv::line(img, point1, point2, 255, 1, LINE_AA);
    }

    Ptr<ORB> orbPtr = ORB::create(31);
    std::vector<KeyPoint> kps;
    Mat fv;
    ASSERT_NO_THROW(orbPtr->detectAndCompute(img, noArray(), kps, fv));
}

TEST(Features2D_ORB, MaskValue)
{
    Mat gray = imread(cvtest::findDataFile("features2d/tsukuba.png"), IMREAD_GRAYSCALE);
    ASSERT_FALSE(gray.empty());

    cv::Rect roi(gray.cols/4, gray.rows/4, gray.cols/2, gray.rows/2);

    Mat mask255 = Mat::zeros(gray.size(), CV_8UC1);
    Mat mask1 = Mat::zeros(gray.size(), CV_8UC1);
    mask255(roi).setTo(255);
    mask1(roi).setTo(1);

    Ptr<ORB> orb = cv::ORB::create();

    vector<KeyPoint> keypoints_mask255, keypoints_mask1;
    Mat descriptors_mask255, descriptors_mask1;

    orb->detectAndCompute(gray, mask255, keypoints_mask255, descriptors_mask255, false);
    orb->detectAndCompute(gray, mask1, keypoints_mask1, descriptors_mask1, false);

    std::cout << "keypoints_mask255.size(): " << keypoints_mask255.size() << std::endl;
    std::cout << "descriptors_mask255.size(): " << descriptors_mask255.size() << std::endl;
    std::cout << "keypoints_mask1.size(): " << keypoints_mask1.size() << std::endl;
    std::cout << "descriptors_mask1.size(): " << descriptors_mask1.size() << std::endl;

    ASSERT_EQ(keypoints_mask255.size(), keypoints_mask1.size())

Review comment (suggestion):
imho refined version of test is better
```
TEST(Features2D_ORB, MaskValue)
{
    Mat gray = imread(cvtest::findDataFile("features2d/tsukuba.png"), IMREAD_GRAYSCALE);
    ASSERT_FALSE(gray.empty());

    cv::Rect roi(gray.cols/4, gray.rows/4, gray.cols/2, gray.rows/2);

    Mat mask255 = Mat::zeros(gray.size(), CV_8UC1);
    Mat mask1 = Mat::zeros(gray.size(), CV_8UC1);
    mask255(roi).setTo(255);
    mask1(roi).setTo(1);

    Ptr<ORB> orb = cv::ORB::create();

    vector<KeyPoint> keypoints_mask255, keypoints_mask1;
    Mat descriptors_mask255, descriptors_mask1;

    orb->detectAndCompute(gray, mask255, keypoints_mask255, descriptors_mask255, false);
    orb->detectAndCompute(gray, mask1, keypoints_mask1, descriptors_mask1, false);

    ASSERT_EQ(keypoints_mask255.size(), keypoints_mask1.size())
        << "Number of keypoints differs between mask values 255 and 1";

    Mat diff = descriptors_mask255 != descriptors_mask1;
    ASSERT_EQ(countNonZero(diff), 0);
}
```

Code after:
{
    applyTestTag(
        CV_TEST_TAG_LONG,
        CV_TEST_TAG_DEBUG_VERYLONG,
        CV_TEST_TAG_MEMORY_6GB
    );

    const int width = 25000;
    const int height = 25000;
    Mat img(Size(width, height), CV_8UC1, Scalar::all(0));

    const int border = 23, num_lines = 23;
    for (int i = 0; i < num_lines; i++)
    {
        cv::Point2i point1(border + i * 100, border + i * 100);
        cv::Point2i point2(width - border - i * 100, height - border * i * 100);
        cv::line(img, point1, point2, 255, 1, LINE_AA);
    }

    Ptr<ORB> orbPtr = ORB::create(31);
    std::vector<KeyPoint> kps;
    Mat fv;
    ASSERT_NO_THROW(orbPtr->detectAndCompute(img, noArray(), kps, fv));
}

TEST(Features2D_ORB, MaskValue)
{
    Mat gray = imread(cvtest::findDataFile("features2d/tsukuba.png"), IMREAD_GRAYSCALE);
    ASSERT_FALSE(gray.empty());

    cv::Rect roi(gray.cols/4, gray.rows/4, gray.cols/2, gray.rows/2);

    Mat mask255 = Mat::zeros(gray.size(), CV_8UC1);
    Mat mask1 = Mat::zeros(gray.size(), CV_8UC1);
    mask255(roi).setTo(255);
    mask1(roi).setTo(1);

    Ptr<ORB> orb = cv::ORB::create();

    vector<KeyPoint> keypoints_mask255, keypoints_mask1;
    Mat descriptors_mask255, descriptors_mask1;

    orb->detectAndCompute(gray, mask255, keypoints_mask255, descriptors_mask255, false);
    orb->detectAndCompute(gray, mask1, keypoints_mask1, descriptors_mask1, false);

    ASSERT_EQ(keypoints_mask255.size(), keypoints_mask1.size())
        << "Number of keypoints differs between mask values 255 and 1";

    Mat diff = descriptors_mask255 != descriptors_mask1;
    ASSERT_EQ(countNonZero(diff), 0);
}