1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html
4
5 #include "test_precomp.hpp"
6
7 namespace opencv_test { namespace {
8
TEST(Features2d_SIFT,descriptor_type)9 TEST(Features2d_SIFT, descriptor_type)
10 {
11 Mat image = imread(cvtest::findDataFile("features2d/tsukuba.png"));
12 ASSERT_FALSE(image.empty());
13
14 Mat gray;
15 cvtColor(image, gray, COLOR_BGR2GRAY);
16
17 vector<KeyPoint> keypoints;
18 Mat descriptorsFloat, descriptorsUchar;
19 Ptr<SIFT> siftFloat = cv::SIFT::create(0, 3, 0.04, 10, 1.6, CV_32F);
20 siftFloat->detectAndCompute(gray, Mat(), keypoints, descriptorsFloat, false);
21 ASSERT_EQ(descriptorsFloat.type(), CV_32F) << "type mismatch";
22
23 Ptr<SIFT> siftUchar = cv::SIFT::create(0, 3, 0.04, 10, 1.6, CV_8U);
24 siftUchar->detectAndCompute(gray, Mat(), keypoints, descriptorsUchar, false);
25 ASSERT_EQ(descriptorsUchar.type(), CV_8U) << "type mismatch";
26
27 Mat descriptorsFloat2;
28 descriptorsUchar.assignTo(descriptorsFloat2, CV_32F);
29 Mat diff = descriptorsFloat != descriptorsFloat2;
30 ASSERT_EQ(countNonZero(diff), 0) << "descriptors are not identical";
31 }
32
33
34 }} // namespace
35