MACE.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. 
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.FaceModule {
  8. // C++: class MACE
  9. //javadoc: MACE
  10. public class MACE : Algorithm {
  11. protected override void Dispose(bool disposing) {
  12. #if (UNITY_ANDROID && !UNITY_EDITOR)
  13. try {
  14. if (disposing) {
  15. }
  16. if (IsEnabledDispose) {
  17. if (nativeObj != IntPtr.Zero)
  18. face_MACE_delete(nativeObj);
  19. nativeObj = IntPtr.Zero;
  20. }
  21. } finally {
  22. base.Dispose(disposing);
  23. }
  24. #else
  25. return;
  26. #endif
  27. }
  28. protected internal MACE(IntPtr addr) : base(addr) { }
  29. // internal usage only
  30. public static new MACE __fromPtr__(IntPtr addr) { return new MACE(addr); }
  31. //
  32. // C++: static Ptr_MACE cv::face::MACE::create(int IMGSIZE = 64)
  33. //
  34. //javadoc: MACE::create(IMGSIZE)
  35. public static MACE create(int IMGSIZE) {
  36. #if (UNITY_ANDROID && !UNITY_EDITOR)
  37. MACE retVal = MACE.__fromPtr__(face_MACE_create_10(IMGSIZE));
  38. return retVal;
  39. #else
  40. return null;
  41. #endif
  42. }
  43. //javadoc: MACE::create()
  44. public static MACE create() {
  45. #if (UNITY_ANDROID && !UNITY_EDITOR)
  46. MACE retVal = MACE.__fromPtr__(face_MACE_create_11());
  47. return retVal;
  48. #else
  49. return null;
  50. #endif
  51. }
  52. //
  53. // C++: static Ptr_MACE cv::face::MACE::load(String filename, String objname = String())
  54. //
  55. //javadoc: MACE::load(filename, objname)
  56. public static MACE load(string filename, string objname) {
  57. #if (UNITY_ANDROID && !UNITY_EDITOR)
  58. MACE retVal = MACE.__fromPtr__(face_MACE_load_10(filename, objname));
  59. return retVal;
  60. #else
  61. return null;
  62. #endif
  63. }
  64. //javadoc: MACE::load(filename)
  65. public static MACE load(string filename) {
  66. #if (UNITY_ANDROID && !UNITY_EDITOR)
  67. MACE retVal = MACE.__fromPtr__(face_MACE_load_11(filename));
  68. return retVal;
  69. #else
  70. return null;
  71. #endif
  72. }
  73. //
  74. // C++: bool cv::face::MACE::same(Mat query)
  75. //
  76. //javadoc: MACE::same(query)
  77. public bool same(Mat query) {
  78. ThrowIfDisposed();
  79. if (query != null) query.ThrowIfDisposed();
  80. #if (UNITY_ANDROID && !UNITY_EDITOR)
  81. bool retVal = face_MACE_same_10(nativeObj, query.nativeObj);
  82. return retVal;
  83. #else
  84. return false;
  85. #endif
  86. }
  87. //
  88. // C++: void cv::face::MACE::salt(String passphrase)
  89. //
  90. //javadoc: MACE::salt(passphrase)
  91. public void salt(string passphrase) {
  92. ThrowIfDisposed();
  93. #if (UNITY_ANDROID && !UNITY_EDITOR)
  94. face_MACE_salt_10(nativeObj, passphrase);
  95. return;
  96. #else
  97. return;
  98. #endif
  99. }
  100. //
  101. // C++: void cv::face::MACE::train(vector_Mat images)
  102. //
  103. //javadoc: MACE::train(images)
  104. public void train(List<Mat> images) {
  105. ThrowIfDisposed();
  106. #if (UNITY_ANDROID && !UNITY_EDITOR)
  107. Mat images_mat = Converters.vector_Mat_to_Mat(images);
  108. face_MACE_train_10(nativeObj, images_mat.nativeObj);
  109. return;
  110. #else
  111. return;
  112. #endif
  113. }
  114. #if (UNITY_ANDROID && !UNITY_EDITOR)
  115. const string LIBNAME = "opencvforunity";
  116. // C++: static Ptr_MACE cv::face::MACE::create(int IMGSIZE = 64)
  117. [DllImport(LIBNAME)]
  118. private static extern IntPtr face_MACE_create_10(int IMGSIZE);
  119. [DllImport(LIBNAME)]
  120. private static extern IntPtr face_MACE_create_11();
  121. // C++: static Ptr_MACE cv::face::MACE::load(String filename, String objname = String())
  122. [DllImport(LIBNAME)]
  123. private static extern IntPtr face_MACE_load_10(string filename, string objname);
  124. [DllImport(LIBNAME)]
  125. private static extern IntPtr face_MACE_load_11(string filename);
  126. // C++: bool cv::face::MACE::same(Mat query)
  127. [DllImport(LIBNAME)]
  128. private static extern bool face_MACE_same_10(IntPtr nativeObj, IntPtr query_nativeObj);
  129. // C++: void cv::face::MACE::salt(String passphrase)
  130. [DllImport(LIBNAME)]
  131. private static extern void face_MACE_salt_10(IntPtr nativeObj, string passphrase);
  132. // C++: void cv::face::MACE::train(vector_Mat images)
  133. [DllImport(LIBNAME)]
  134. private static extern void face_MACE_train_10(IntPtr nativeObj, IntPtr images_mat_nativeObj);
  135. // native support for java finalize()
  136. [DllImport(LIBNAME)]
  137. private static extern void face_MACE_delete(IntPtr nativeObj);
  138. #endif
  139. }
  140. }