test_akaze.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_AKAZE, detect_and_compute_split)
  7. {
  8. Mat testImg(100, 100, CV_8U);
  9. RNG rng(101);
  10. rng.fill(testImg, RNG::UNIFORM, Scalar(0), Scalar(255), true);
  11. Ptr<Feature2D> ext = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 0, 3, 0.001f, 1, 1, KAZE::DIFF_PM_G2);
  12. vector<KeyPoint> detAndCompKps;
  13. Mat desc;
  14. ext->detectAndCompute(testImg, noArray(), detAndCompKps, desc);
  15. vector<KeyPoint> detKps;
  16. ext->detect(testImg, detKps);
  17. ASSERT_EQ(detKps.size(), detAndCompKps.size());
  18. for(size_t i = 0; i < detKps.size(); i++)
  19. ASSERT_EQ(detKps[i].hash(), detAndCompKps[i].hash());
  20. }
  21. /**
  22. * This test is here to guard propagation of NaNs that happens on this image. NaNs are guarded
  23. * by debug asserts in AKAZE, which should fire for you if you are lucky.
  24. *
  25. * This test also reveals problems with uninitialized memory that happens only on this image.
  26. * This is very hard to hit and depends a lot on particular allocator. Run this test in valgrind and check
  27. * for uninitialized values if you think you are hitting this problem again.
  28. */
  29. TEST(Features2d_AKAZE, uninitialized_and_nans)
  30. {
  31. Mat b1 = imread(cvtest::TS::ptr()->get_data_path() + "../stitching/b1.png");
  32. ASSERT_FALSE(b1.empty());
  33. vector<KeyPoint> keypoints;
  34. Mat desc;
  35. Ptr<Feature2D> akaze = AKAZE::create();
  36. akaze->detectAndCompute(b1, noArray(), keypoints, desc);
  37. }
  38. }} // namespace