test_sift.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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. #include "test_precomp.hpp"
  5. namespace opencv_test { namespace {
  6. TEST(Features2d_SIFT, descriptor_type)
  7. {
  8. Mat image = imread(cvtest::findDataFile("features2d/tsukuba.png"));
  9. ASSERT_FALSE(image.empty());
  10. Mat gray;
  11. cvtColor(image, gray, COLOR_BGR2GRAY);
  12. vector<KeyPoint> keypoints;
  13. Mat descriptorsFloat, descriptorsUchar;
  14. Ptr<SIFT> siftFloat = cv::SIFT::create(0, 3, 0.04, 10, 1.6, CV_32F);
  15. siftFloat->detectAndCompute(gray, Mat(), keypoints, descriptorsFloat, false);
  16. ASSERT_EQ(descriptorsFloat.type(), CV_32F) << "type mismatch";
  17. Ptr<SIFT> siftUchar = cv::SIFT::create(0, 3, 0.04, 10, 1.6, CV_8U);
  18. siftUchar->detectAndCompute(gray, Mat(), keypoints, descriptorsUchar, false);
  19. ASSERT_EQ(descriptorsUchar.type(), CV_8U) << "type mismatch";
  20. Mat descriptorsFloat2;
  21. descriptorsUchar.assignTo(descriptorsFloat2, CV_32F);
  22. Mat diff = descriptorsFloat != descriptorsFloat2;
  23. ASSERT_EQ(countNonZero(diff), 0) << "descriptors are not identical";
  24. }
  25. }} // namespace