test_marr_hildreth_hash.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. class CV_MarrHildrethTest : public cvtest::BaseTest
  7. {
  8. public:
  9. CV_MarrHildrethTest();
  10. ~CV_MarrHildrethTest();
  11. protected:
  12. void run(int /* idx */);
  13. };
  14. CV_MarrHildrethTest::CV_MarrHildrethTest(){}
  15. CV_MarrHildrethTest::~CV_MarrHildrethTest(){}
  16. void CV_MarrHildrethTest::run(int )
  17. {
  18. cv::Mat_<uchar> input(512,512);
  19. int val = 0;
  20. for(int row = 0; row != input.rows; ++row)
  21. {
  22. for(int col = 0; col != input.cols; ++col)
  23. {
  24. input.at<uchar>(row, col) = val % 256;
  25. ++val;
  26. }
  27. }
  28. cv::Mat hash;
  29. cv::img_hash::marrHildrethHash(input, hash);
  30. uchar const expectResult[] =
  31. {
  32. 252, 126, 63, 31, 143, 199, 227, 241,
  33. 248, 252, 126, 63, 31, 143, 199, 227,
  34. 241, 248, 252, 126, 63, 31, 143, 199,
  35. 227, 241, 248, 252, 126, 63, 31, 143,
  36. 199, 227, 241, 248, 31, 143, 199, 227,
  37. 241, 248, 252, 126, 63, 252, 126, 63,
  38. 31, 143, 199, 227, 241, 248, 252, 126,
  39. 63, 31, 143, 199, 227, 241, 248, 252,
  40. 126, 63, 31, 143, 199, 227, 241, 248
  41. };
  42. uchar const *hashPtr = hash.ptr<uchar>(0);
  43. for(int i = 0; i != 72; ++i)
  44. {
  45. if(hashPtr[i] != expectResult[i])
  46. {
  47. ts->printf(cvtest::TS::LOG, "Wrong hash value \n");
  48. ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
  49. return;
  50. }
  51. }
  52. }
  53. TEST(marr_hildreth_test, accuracy) { CV_MarrHildrethTest test; test.safe_run(); }
  54. }} // namespace