mace.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef __mace_h_onboard__
  5. #define __mace_h_onboard__
  6. #include "opencv2/core.hpp"
  7. namespace cv {
  8. namespace face {
  9. //! @addtogroup face
  10. //! @{
  11. /**
  12. @brief Minimum Average Correlation Energy Filter
  13. useful for authentication with (cancellable) biometrical features.
  14. (does not need many positives to train (10-50), and no negatives at all, also robust to noise/salting)
  15. see also: @cite Savvides04
  16. this implementation is largely based on: https://code.google.com/archive/p/pam-face-authentication (GSOC 2009)
  17. use it like:
  18. @code
  19. Ptr<face::MACE> mace = face::MACE::create(64);
  20. vector<Mat> pos_images = ...
  21. mace->train(pos_images);
  22. Mat query = ...
  23. bool same = mace->same(query);
  24. @endcode
  25. you can also use two-factor authentication, with an additional passphrase:
  26. @code
  27. String owners_passphrase = "ilikehotdogs";
  28. Ptr<face::MACE> mace = face::MACE::create(64);
  29. mace->salt(owners_passphrase);
  30. vector<Mat> pos_images = ...
  31. mace->train(pos_images);
  32. // now, users have to give a valid passphrase, along with the image:
  33. Mat query = ...
  34. cout << "enter passphrase: ";
  35. string pass;
  36. getline(cin, pass);
  37. mace->salt(pass);
  38. bool same = mace->same(query);
  39. @endcode
  40. save/load your model:
  41. @code
  42. Ptr<face::MACE> mace = face::MACE::create(64);
  43. mace->train(pos_images);
  44. mace->save("my_mace.xml");
  45. // later:
  46. Ptr<MACE> reloaded = MACE::load("my_mace.xml");
  47. reloaded->same(some_image);
  48. @endcode
  49. */
  50. class CV_EXPORTS_W MACE : public cv::Algorithm
  51. {
  52. public:
  53. /**
  54. @brief optionally encrypt images with random convolution
  55. @param passphrase a crc64 random seed will get generated from this
  56. */
  57. CV_WRAP virtual void salt(const cv::String &passphrase) = 0;
  58. /**
  59. @brief train it on positive features
  60. compute the mace filter: `h = D(-1) * X * (X(+) * D(-1) * X)(-1) * C`
  61. also calculate a minimal threshold for this class, the smallest self-similarity from the train images
  62. @param images a vector<Mat> with the train images
  63. */
  64. CV_WRAP virtual void train(cv::InputArrayOfArrays images) = 0;
  65. /**
  66. @brief correlate query img and threshold to min class value
  67. @param query a Mat with query image
  68. */
  69. CV_WRAP virtual bool same(cv::InputArray query) const = 0;
  70. /**
  71. @brief constructor
  72. @param filename build a new MACE instance from a pre-serialized FileStorage
  73. @param objname (optional) top-level node in the FileStorage
  74. */
  75. CV_WRAP static cv::Ptr<MACE> load(const String &filename, const String &objname=String());
  76. /**
  77. @brief constructor
  78. @param IMGSIZE images will get resized to this (should be an even number)
  79. */
  80. CV_WRAP static cv::Ptr<MACE> create(int IMGSIZE=64);
  81. };
  82. //! @}
  83. }/* namespace face */
  84. }/* namespace cv */
  85. #endif // __mace_h_onboard__