FisherFaceRecognizer.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 FisherFaceRecognizer
  9. public class FisherFaceRecognizer : 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_FisherFaceRecognizer_delete(nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. }
  25. finally
  26. {
  27. base.Dispose(disposing);
  28. }
  29. }
  30. protected internal FisherFaceRecognizer(IntPtr addr) : base(addr) { }
  31. // internal usage only
  32. public static new FisherFaceRecognizer __fromPtr__(IntPtr addr) { return new FisherFaceRecognizer(addr); }
  33. //
  34. // C++: static Ptr_FisherFaceRecognizer cv::face::FisherFaceRecognizer::create(int num_components = 0, double threshold = DBL_MAX)
  35. //
  36. /**
  37. * param num_components The number of components (read: Fisherfaces) kept for this Linear
  38. * Discriminant Analysis with the Fisherfaces criterion. It's useful to keep all components, that
  39. * means the number of your classes c (read: subjects, persons you want to recognize). If you leave
  40. * this at the default (0) or set it to a value less-equal 0 or greater (c-1), it will be set to the
  41. * correct number (c-1) automatically.
  42. * param threshold The threshold applied in the prediction. If the distance to the nearest neighbor
  43. * is larger than the threshold, this method returns -1.
  44. *
  45. * ### Notes:
  46. *
  47. * <ul>
  48. * <li>
  49. * Training and prediction must be done on grayscale images, use cvtColor to convert between the
  50. * color spaces.
  51. * </li>
  52. * <li>
  53. * <b>THE FISHERFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL
  54. * SIZE.</b> (caps-lock, because I got so many mails asking for this). You have to make sure your
  55. * input data has the correct shape, else a meaningful exception is thrown. Use resize to resize
  56. * the images.
  57. * </li>
  58. * <li>
  59. * This model does not support updating.
  60. * </li>
  61. * </ul>
  62. *
  63. * ### Model internal data:
  64. *
  65. * <ul>
  66. * <li>
  67. * num_components see FisherFaceRecognizer::create.
  68. * </li>
  69. * <li>
  70. * threshold see FisherFaceRecognizer::create.
  71. * </li>
  72. * <li>
  73. * eigenvalues The eigenvalues for this Linear Discriminant Analysis (ordered descending).
  74. * </li>
  75. * <li>
  76. * eigenvectors The eigenvectors for this Linear Discriminant Analysis (ordered by their
  77. * eigenvalue).
  78. * </li>
  79. * <li>
  80. * mean The sample mean calculated from the training data.
  81. * </li>
  82. * <li>
  83. * projections The projections of the training data.
  84. * </li>
  85. * <li>
  86. * labels The labels corresponding to the projections.
  87. * </li>
  88. * </ul>
  89. * return automatically generated
  90. */
  91. public static FisherFaceRecognizer create(int num_components, double threshold)
  92. {
  93. return FisherFaceRecognizer.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(face_FisherFaceRecognizer_create_10(num_components, threshold)));
  94. }
  95. /**
  96. * param num_components The number of components (read: Fisherfaces) kept for this Linear
  97. * Discriminant Analysis with the Fisherfaces criterion. It's useful to keep all components, that
  98. * means the number of your classes c (read: subjects, persons you want to recognize). If you leave
  99. * this at the default (0) or set it to a value less-equal 0 or greater (c-1), it will be set to the
  100. * correct number (c-1) automatically.
  101. * is larger than the threshold, this method returns -1.
  102. *
  103. * ### Notes:
  104. *
  105. * <ul>
  106. * <li>
  107. * Training and prediction must be done on grayscale images, use cvtColor to convert between the
  108. * color spaces.
  109. * </li>
  110. * <li>
  111. * <b>THE FISHERFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL
  112. * SIZE.</b> (caps-lock, because I got so many mails asking for this). You have to make sure your
  113. * input data has the correct shape, else a meaningful exception is thrown. Use resize to resize
  114. * the images.
  115. * </li>
  116. * <li>
  117. * This model does not support updating.
  118. * </li>
  119. * </ul>
  120. *
  121. * ### Model internal data:
  122. *
  123. * <ul>
  124. * <li>
  125. * num_components see FisherFaceRecognizer::create.
  126. * </li>
  127. * <li>
  128. * threshold see FisherFaceRecognizer::create.
  129. * </li>
  130. * <li>
  131. * eigenvalues The eigenvalues for this Linear Discriminant Analysis (ordered descending).
  132. * </li>
  133. * <li>
  134. * eigenvectors The eigenvectors for this Linear Discriminant Analysis (ordered by their
  135. * eigenvalue).
  136. * </li>
  137. * <li>
  138. * mean The sample mean calculated from the training data.
  139. * </li>
  140. * <li>
  141. * projections The projections of the training data.
  142. * </li>
  143. * <li>
  144. * labels The labels corresponding to the projections.
  145. * </li>
  146. * </ul>
  147. * return automatically generated
  148. */
  149. public static FisherFaceRecognizer create(int num_components)
  150. {
  151. return FisherFaceRecognizer.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(face_FisherFaceRecognizer_create_11(num_components)));
  152. }
  153. /**
  154. * Discriminant Analysis with the Fisherfaces criterion. It's useful to keep all components, that
  155. * means the number of your classes c (read: subjects, persons you want to recognize). If you leave
  156. * this at the default (0) or set it to a value less-equal 0 or greater (c-1), it will be set to the
  157. * correct number (c-1) automatically.
  158. * is larger than the threshold, this method returns -1.
  159. *
  160. * ### Notes:
  161. *
  162. * <ul>
  163. * <li>
  164. * Training and prediction must be done on grayscale images, use cvtColor to convert between the
  165. * color spaces.
  166. * </li>
  167. * <li>
  168. * <b>THE FISHERFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL
  169. * SIZE.</b> (caps-lock, because I got so many mails asking for this). You have to make sure your
  170. * input data has the correct shape, else a meaningful exception is thrown. Use resize to resize
  171. * the images.
  172. * </li>
  173. * <li>
  174. * This model does not support updating.
  175. * </li>
  176. * </ul>
  177. *
  178. * ### Model internal data:
  179. *
  180. * <ul>
  181. * <li>
  182. * num_components see FisherFaceRecognizer::create.
  183. * </li>
  184. * <li>
  185. * threshold see FisherFaceRecognizer::create.
  186. * </li>
  187. * <li>
  188. * eigenvalues The eigenvalues for this Linear Discriminant Analysis (ordered descending).
  189. * </li>
  190. * <li>
  191. * eigenvectors The eigenvectors for this Linear Discriminant Analysis (ordered by their
  192. * eigenvalue).
  193. * </li>
  194. * <li>
  195. * mean The sample mean calculated from the training data.
  196. * </li>
  197. * <li>
  198. * projections The projections of the training data.
  199. * </li>
  200. * <li>
  201. * labels The labels corresponding to the projections.
  202. * </li>
  203. * </ul>
  204. * return automatically generated
  205. */
  206. public static FisherFaceRecognizer create()
  207. {
  208. return FisherFaceRecognizer.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(face_FisherFaceRecognizer_create_12()));
  209. }
  210. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  211. const string LIBNAME = "__Internal";
  212. #else
  213. const string LIBNAME = "opencvforunity";
  214. #endif
  215. // C++: static Ptr_FisherFaceRecognizer cv::face::FisherFaceRecognizer::create(int num_components = 0, double threshold = DBL_MAX)
  216. [DllImport(LIBNAME)]
  217. private static extern IntPtr face_FisherFaceRecognizer_create_10(int num_components, double threshold);
  218. [DllImport(LIBNAME)]
  219. private static extern IntPtr face_FisherFaceRecognizer_create_11(int num_components);
  220. [DllImport(LIBNAME)]
  221. private static extern IntPtr face_FisherFaceRecognizer_create_12();
  222. // native support for java finalize()
  223. [DllImport(LIBNAME)]
  224. private static extern void face_FisherFaceRecognizer_delete(IntPtr nativeObj);
  225. }
  226. }