facemarkAAM.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. By downloading, copying, installing or using the software you agree to this
  3. license. If you do not agree to this license, do not download, install,
  4. copy or use the software.
  5. License Agreement
  6. For Open Source Computer Vision Library
  7. (3-clause BSD License)
  8. Copyright (C) 2013, OpenCV Foundation, all rights reserved.
  9. Third party copyrights are property of their respective owners.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. * Neither the names of the copyright holders nor the names of the contributors
  18. may be used to endorse or promote products derived from this software
  19. without specific prior written permission.
  20. This software is provided by the copyright holders and contributors "as is" and
  21. any express or implied warranties, including, but not limited to, the implied
  22. warranties of merchantability and fitness for a particular purpose are
  23. disclaimed. In no event shall copyright holders or contributors be liable for
  24. any direct, indirect, incidental, special, exemplary, or consequential damages
  25. (including, but not limited to, procurement of substitute goods or services;
  26. loss of use, data, or profits; or business interruption) however caused
  27. and on any theory of liability, whether in contract, strict liability,
  28. or tort (including negligence or otherwise) arising in any way out of
  29. the use of this software, even if advised of the possibility of such damage.
  30. This file was part of GSoC Project: Facemark API for OpenCV
  31. Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc
  32. Student: Laksono Kurnianggoro
  33. Mentor: Delia Passalacqua
  34. */
  35. #ifndef __OPENCV_FACEMARK_AAM_HPP__
  36. #define __OPENCV_FACEMARK_AAM_HPP__
  37. #include "opencv2/face/facemark_train.hpp"
  38. namespace cv {
  39. namespace face {
  40. //! @addtogroup face
  41. //! @{
  42. class CV_EXPORTS_W FacemarkAAM : public FacemarkTrain
  43. {
  44. public:
  45. struct CV_EXPORTS Params
  46. {
  47. /**
  48. * \brief Constructor
  49. */
  50. Params();
  51. /**
  52. * \brief Read parameters from file, currently unused
  53. */
  54. void read(const FileNode& /*fn*/);
  55. /**
  56. * \brief Read parameters from file, currently unused
  57. */
  58. void write(FileStorage& /*fs*/) const;
  59. std::string model_filename;
  60. int m;
  61. int n;
  62. int n_iter;
  63. bool verbose;
  64. bool save_model;
  65. int max_m, max_n, texture_max_m;
  66. std::vector<float>scales;
  67. };
  68. /**
  69. * \brief Optional parameter for fitting process.
  70. */
  71. struct CV_EXPORTS Config
  72. {
  73. Config( Mat rot = Mat::eye(2,2,CV_32F),
  74. Point2f trans = Point2f(0.0f, 0.0f),
  75. float scaling = 1.0f,
  76. int scale_id=0
  77. );
  78. Mat R;
  79. Point2f t;
  80. float scale;
  81. int model_scale_idx;
  82. };
  83. /**
  84. * \brief Data container for the facemark::getData function
  85. */
  86. struct CV_EXPORTS Data
  87. {
  88. std::vector<Point2f> s0;
  89. };
  90. /**
  91. * \brief The model of AAM Algorithm
  92. */
  93. struct CV_EXPORTS Model
  94. {
  95. std::vector<float>scales;
  96. //!< defines the scales considered to build the model
  97. /*warping*/
  98. std::vector<Vec3i> triangles;
  99. //!< each element contains 3 values, represent index of facemarks that construct one triangle (obtained using delaunay triangulation)
  100. struct Texture{
  101. int max_m; //!< unused delete
  102. Rect resolution;
  103. //!< resolution of the current scale
  104. Mat A;
  105. //!< gray values from all face region in the dataset, projected in PCA space
  106. Mat A0;
  107. //!< average of gray values from all face region in the dataset
  108. Mat AA;
  109. //!< gray values from all erorded face region in the dataset, projected in PCA space
  110. Mat AA0;
  111. //!< average of gray values from all erorded face region in the dataset
  112. std::vector<std::vector<Point> > textureIdx;
  113. //!< index for warping of each delaunay triangle region constructed by 3 facemarks
  114. std::vector<Point2f> base_shape;
  115. //!< basic shape, normalized to be fit in an image with current detection resolution
  116. std::vector<int> ind1;
  117. //!< index of pixels for mapping process to obtains the grays values of face region
  118. std::vector<int> ind2;
  119. //!< index of pixels for mapping process to obtains the grays values of eroded face region
  120. };
  121. std::vector<Texture> textures;
  122. //!< a container to holds the texture data for each scale of fitting
  123. /*shape*/
  124. std::vector<Point2f> s0;
  125. //!< the basic shape obtained from training dataset
  126. Mat S,Q;
  127. //!< the encoded shapes from training data
  128. };
  129. //! overload with additional Config structures
  130. virtual bool fitConfig( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks, const std::vector<Config> &runtime_params ) = 0;
  131. //! initializer
  132. static Ptr<FacemarkAAM> create(const FacemarkAAM::Params &parameters = FacemarkAAM::Params() );
  133. virtual ~FacemarkAAM() {}
  134. }; /* AAM */
  135. //! @}
  136. } /* namespace face */
  137. } /* namespace cv */
  138. #endif