EigenFaceRecognizer.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.FaceModule
  7. {
  8. // C++: class EigenFaceRecognizer
  9. public class EigenFaceRecognizer : BasicFaceRecognizer
  10. {
  11. protected override void Dispose(bool disposing)
  12. {
  13. try
  14. {
  15. if (disposing)
  16. {
  17. }
  18. if (IsEnabledDispose)
  19. {
  20. if (nativeObj != IntPtr.Zero)
  21. face_EigenFaceRecognizer_delete(nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. }
  25. finally
  26. {
  27. base.Dispose(disposing);
  28. }
  29. }
  30. protected internal EigenFaceRecognizer(IntPtr addr) : base(addr) { }
  31. // internal usage only
  32. public static new EigenFaceRecognizer __fromPtr__(IntPtr addr) { return new EigenFaceRecognizer(addr); }
  33. //
  34. // C++: static Ptr_EigenFaceRecognizer cv::face::EigenFaceRecognizer::create(int num_components = 0, double threshold = DBL_MAX)
  35. //
  36. /**
  37. * param num_components The number of components (read: Eigenfaces) kept for this Principal
  38. * Component Analysis. As a hint: There's no rule how many components (read: Eigenfaces) should be
  39. * kept for good reconstruction capabilities. It is based on your input data, so experiment with the
  40. * number. Keeping 80 components should almost always be sufficient.
  41. * param threshold The threshold applied in the prediction.
  42. *
  43. * ### Notes:
  44. *
  45. * <ul>
  46. * <li>
  47. * Training and prediction must be done on grayscale images, use cvtColor to convert between the
  48. * color spaces.
  49. * </li>
  50. * <li>
  51. * <b>THE EIGENFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL
  52. * SIZE.</b> (caps-lock, because I got so many mails asking for this). You have to make sure your
  53. * input data has the correct shape, else a meaningful exception is thrown. Use resize to resize
  54. * the images.
  55. * </li>
  56. * <li>
  57. * This model does not support updating.
  58. * </li>
  59. * </ul>
  60. *
  61. * ### Model internal data:
  62. *
  63. * <ul>
  64. * <li>
  65. * num_components see EigenFaceRecognizer::create.
  66. * </li>
  67. * <li>
  68. * threshold see EigenFaceRecognizer::create.
  69. * </li>
  70. * <li>
  71. * eigenvalues The eigenvalues for this Principal Component Analysis (ordered descending).
  72. * </li>
  73. * <li>
  74. * eigenvectors The eigenvectors for this Principal Component Analysis (ordered by their
  75. * eigenvalue).
  76. * </li>
  77. * <li>
  78. * mean The sample mean calculated from the training data.
  79. * </li>
  80. * <li>
  81. * projections The projections of the training data.
  82. * </li>
  83. * <li>
  84. * labels The threshold applied in the prediction. If the distance to the nearest neighbor is
  85. * larger than the threshold, this method returns -1.
  86. * </li>
  87. * </ul>
  88. * return automatically generated
  89. */
  90. public static EigenFaceRecognizer create(int num_components, double threshold)
  91. {
  92. return EigenFaceRecognizer.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(face_EigenFaceRecognizer_create_10(num_components, threshold)));
  93. }
  94. /**
  95. * param num_components The number of components (read: Eigenfaces) kept for this Principal
  96. * Component Analysis. As a hint: There's no rule how many components (read: Eigenfaces) should be
  97. * kept for good reconstruction capabilities. It is based on your input data, so experiment with the
  98. * number. Keeping 80 components should almost always be sufficient.
  99. *
  100. * ### Notes:
  101. *
  102. * <ul>
  103. * <li>
  104. * Training and prediction must be done on grayscale images, use cvtColor to convert between the
  105. * color spaces.
  106. * </li>
  107. * <li>
  108. * <b>THE EIGENFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL
  109. * SIZE.</b> (caps-lock, because I got so many mails asking for this). You have to make sure your
  110. * input data has the correct shape, else a meaningful exception is thrown. Use resize to resize
  111. * the images.
  112. * </li>
  113. * <li>
  114. * This model does not support updating.
  115. * </li>
  116. * </ul>
  117. *
  118. * ### Model internal data:
  119. *
  120. * <ul>
  121. * <li>
  122. * num_components see EigenFaceRecognizer::create.
  123. * </li>
  124. * <li>
  125. * threshold see EigenFaceRecognizer::create.
  126. * </li>
  127. * <li>
  128. * eigenvalues The eigenvalues for this Principal Component Analysis (ordered descending).
  129. * </li>
  130. * <li>
  131. * eigenvectors The eigenvectors for this Principal Component Analysis (ordered by their
  132. * eigenvalue).
  133. * </li>
  134. * <li>
  135. * mean The sample mean calculated from the training data.
  136. * </li>
  137. * <li>
  138. * projections The projections of the training data.
  139. * </li>
  140. * <li>
  141. * labels The threshold applied in the prediction. If the distance to the nearest neighbor is
  142. * larger than the threshold, this method returns -1.
  143. * </li>
  144. * </ul>
  145. * return automatically generated
  146. */
  147. public static EigenFaceRecognizer create(int num_components)
  148. {
  149. return EigenFaceRecognizer.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(face_EigenFaceRecognizer_create_11(num_components)));
  150. }
  151. /**
  152. * Component Analysis. As a hint: There's no rule how many components (read: Eigenfaces) should be
  153. * kept for good reconstruction capabilities. It is based on your input data, so experiment with the
  154. * number. Keeping 80 components should almost always be sufficient.
  155. *
  156. * ### Notes:
  157. *
  158. * <ul>
  159. * <li>
  160. * Training and prediction must be done on grayscale images, use cvtColor to convert between the
  161. * color spaces.
  162. * </li>
  163. * <li>
  164. * <b>THE EIGENFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL
  165. * SIZE.</b> (caps-lock, because I got so many mails asking for this). You have to make sure your
  166. * input data has the correct shape, else a meaningful exception is thrown. Use resize to resize
  167. * the images.
  168. * </li>
  169. * <li>
  170. * This model does not support updating.
  171. * </li>
  172. * </ul>
  173. *
  174. * ### Model internal data:
  175. *
  176. * <ul>
  177. * <li>
  178. * num_components see EigenFaceRecognizer::create.
  179. * </li>
  180. * <li>
  181. * threshold see EigenFaceRecognizer::create.
  182. * </li>
  183. * <li>
  184. * eigenvalues The eigenvalues for this Principal Component Analysis (ordered descending).
  185. * </li>
  186. * <li>
  187. * eigenvectors The eigenvectors for this Principal Component Analysis (ordered by their
  188. * eigenvalue).
  189. * </li>
  190. * <li>
  191. * mean The sample mean calculated from the training data.
  192. * </li>
  193. * <li>
  194. * projections The projections of the training data.
  195. * </li>
  196. * <li>
  197. * labels The threshold applied in the prediction. If the distance to the nearest neighbor is
  198. * larger than the threshold, this method returns -1.
  199. * </li>
  200. * </ul>
  201. * return automatically generated
  202. */
  203. public static EigenFaceRecognizer create()
  204. {
  205. return EigenFaceRecognizer.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(face_EigenFaceRecognizer_create_12()));
  206. }
  207. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  208. const string LIBNAME = "__Internal";
  209. #else
  210. const string LIBNAME = "opencvforunity";
  211. #endif
  212. // C++: static Ptr_EigenFaceRecognizer cv::face::EigenFaceRecognizer::create(int num_components = 0, double threshold = DBL_MAX)
  213. [DllImport(LIBNAME)]
  214. private static extern IntPtr face_EigenFaceRecognizer_create_10(int num_components, double threshold);
  215. [DllImport(LIBNAME)]
  216. private static extern IntPtr face_EigenFaceRecognizer_create_11(int num_components);
  217. [DllImport(LIBNAME)]
  218. private static extern IntPtr face_EigenFaceRecognizer_create_12();
  219. // native support for java finalize()
  220. [DllImport(LIBNAME)]
  221. private static extern void face_EigenFaceRecognizer_delete(IntPtr nativeObj);
  222. }
  223. }