BIF.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 BIF
  9. /**
  10. * Implementation of bio-inspired features (BIF) from the paper:
  11. * Guo, Guodong, et al. "Human age estimation using bio-inspired features."
  12. * Computer Vision and Pattern Recognition, 2009. CVPR 2009.
  13. */
  14. public class BIF : Algorithm
  15. {
  16. protected override void Dispose(bool disposing)
  17. {
  18. try
  19. {
  20. if (disposing)
  21. {
  22. }
  23. if (IsEnabledDispose)
  24. {
  25. if (nativeObj != IntPtr.Zero)
  26. face_BIF_delete(nativeObj);
  27. nativeObj = IntPtr.Zero;
  28. }
  29. }
  30. finally
  31. {
  32. base.Dispose(disposing);
  33. }
  34. }
  35. protected internal BIF(IntPtr addr) : base(addr) { }
  36. // internal usage only
  37. public static new BIF __fromPtr__(IntPtr addr) { return new BIF(addr); }
  38. //
  39. // C++: int cv::face::BIF::getNumBands()
  40. //
  41. /**
  42. * return The number of filter bands used for computing BIF.
  43. */
  44. public int getNumBands()
  45. {
  46. ThrowIfDisposed();
  47. return face_BIF_getNumBands_10(nativeObj);
  48. }
  49. //
  50. // C++: int cv::face::BIF::getNumRotations()
  51. //
  52. /**
  53. * return The number of image rotations.
  54. */
  55. public int getNumRotations()
  56. {
  57. ThrowIfDisposed();
  58. return face_BIF_getNumRotations_10(nativeObj);
  59. }
  60. //
  61. // C++: void cv::face::BIF::compute(Mat image, Mat& features)
  62. //
  63. /**
  64. * Computes features sby input image.
  65. * param image Input image (CV_32FC1).
  66. * param features Feature vector (CV_32FC1).
  67. */
  68. public void compute(Mat image, Mat features)
  69. {
  70. ThrowIfDisposed();
  71. if (image != null) image.ThrowIfDisposed();
  72. if (features != null) features.ThrowIfDisposed();
  73. face_BIF_compute_10(nativeObj, image.nativeObj, features.nativeObj);
  74. }
  75. //
  76. // C++: static Ptr_BIF cv::face::BIF::create(int num_bands = 8, int num_rotations = 12)
  77. //
  78. /**
  79. * param num_bands The number of filter bands (<=8) used for computing BIF.
  80. * param num_rotations The number of image rotations for computing BIF.
  81. * return Object for computing BIF.
  82. */
  83. public static BIF create(int num_bands, int num_rotations)
  84. {
  85. return BIF.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(face_BIF_create_10(num_bands, num_rotations)));
  86. }
  87. /**
  88. * param num_bands The number of filter bands (<=8) used for computing BIF.
  89. * return Object for computing BIF.
  90. */
  91. public static BIF create(int num_bands)
  92. {
  93. return BIF.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(face_BIF_create_11(num_bands)));
  94. }
  95. /**
  96. * return Object for computing BIF.
  97. */
  98. public static BIF create()
  99. {
  100. return BIF.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(face_BIF_create_12()));
  101. }
  102. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  103. const string LIBNAME = "__Internal";
  104. #else
  105. const string LIBNAME = "opencvforunity";
  106. #endif
  107. // C++: int cv::face::BIF::getNumBands()
  108. [DllImport(LIBNAME)]
  109. private static extern int face_BIF_getNumBands_10(IntPtr nativeObj);
  110. // C++: int cv::face::BIF::getNumRotations()
  111. [DllImport(LIBNAME)]
  112. private static extern int face_BIF_getNumRotations_10(IntPtr nativeObj);
  113. // C++: void cv::face::BIF::compute(Mat image, Mat& features)
  114. [DllImport(LIBNAME)]
  115. private static extern void face_BIF_compute_10(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr features_nativeObj);
  116. // C++: static Ptr_BIF cv::face::BIF::create(int num_bands = 8, int num_rotations = 12)
  117. [DllImport(LIBNAME)]
  118. private static extern IntPtr face_BIF_create_10(int num_bands, int num_rotations);
  119. [DllImport(LIBNAME)]
  120. private static extern IntPtr face_BIF_create_11(int num_bands);
  121. [DllImport(LIBNAME)]
  122. private static extern IntPtr face_BIF_create_12();
  123. // native support for java finalize()
  124. [DllImport(LIBNAME)]
  125. private static extern void face_BIF_delete(IntPtr nativeObj);
  126. }
  127. }