test_mace.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // This file is part of the 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. #include <fstream>
  6. namespace opencv_test { namespace {
  7. const string FACE_DIR = "face";
  8. const int WINDOW_SIZE = 64;
  9. class MaceTest
  10. {
  11. public:
  12. MaceTest(bool salt);
  13. void run();
  14. protected:
  15. Ptr<MACE> mace;
  16. bool salt;
  17. };
  18. MaceTest::MaceTest(bool use_salt)
  19. {
  20. mace = MACE::create(WINDOW_SIZE);
  21. salt = use_salt;
  22. }
  23. void MaceTest::run()
  24. {
  25. Rect david1 (125,66,58,56);
  26. Rect david2 (132,69,73,74);
  27. Rect detect (199,124,256,274);
  28. string folder = cvtest::TS::ptr()->get_data_path() + FACE_DIR;
  29. Mat train = imread(folder + "/david2.jpg", 0);
  30. Mat tst_p = imread(folder + "/david1.jpg", 0);
  31. Mat tst_n = imread(folder + "/detect.jpg", 0);
  32. vector<Mat> sam_train;
  33. sam_train.push_back( train(Rect(132,69,73,74)) );
  34. sam_train.push_back( train(Rect(130,69,73,72)) );
  35. sam_train.push_back( train(Rect(134,67,73,74)) );
  36. sam_train.push_back( tst_p(Rect(125,66,58,56)) );
  37. sam_train.push_back( tst_p(Rect(123,67,55,58)) );
  38. sam_train.push_back( tst_p(Rect(125,65,58,60)) );
  39. if (salt) mace->salt("it's david"); // "owner's" salt
  40. mace->train(sam_train);
  41. bool self_ok = mace->same(train(david2));
  42. if (salt) mace->salt("this is a test"); // "other's" salt
  43. bool false_A = mace->same(tst_n(detect));
  44. ASSERT_TRUE(self_ok);
  45. ASSERT_FALSE(false_A);
  46. }
  47. TEST(MACE_, unsalted)
  48. {
  49. MaceTest test(false); test.run();
  50. }
  51. TEST(MACE_, salted)
  52. {
  53. MaceTest test(true); test.run();
  54. }
  55. }} // namespace