FacemarkTrain.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 FacemarkTrain
  9. /**
  10. * Abstract base class for trainable facemark models
  11. *
  12. * To utilize this API in your program, please take a look at the REF: tutorial_table_of_content_facemark
  13. * ### Description
  14. *
  15. * The AAM and LBF facemark models in OpenCV are derived from the abstract base class FacemarkTrain, which
  16. * provides a unified access to those facemark algorithms in OpenCV.
  17. *
  18. * Here is an example on how to declare facemark algorithm:
  19. * <code>
  20. * // Using Facemark in your code:
  21. * Ptr&lt;Facemark&gt; facemark = FacemarkLBF::create();
  22. * </code>
  23. *
  24. *
  25. * The typical pipeline for facemark detection is listed as follows:
  26. * <ul>
  27. * <li>
  28. * (Non-mandatory) Set a user defined face detection using FacemarkTrain::setFaceDetector.
  29. * The facemark algorithms are designed to fit the facial points into a face.
  30. * Therefore, the face information should be provided to the facemark algorithm.
  31. * Some algorithms might provides a default face recognition function.
  32. * However, the users might prefer to use their own face detector to obtains the best possible detection result.
  33. * </li>
  34. * <li>
  35. * (Non-mandatory) Training the model for a specific algorithm using FacemarkTrain::training.
  36. * In this case, the model should be automatically saved by the algorithm.
  37. * If the user already have a trained model, then this part can be omitted.
  38. * </li>
  39. * <li>
  40. * Load the trained model using Facemark::loadModel.
  41. * </li>
  42. * <li>
  43. * Perform the fitting via the Facemark::fit.
  44. * </li>
  45. * </ul>
  46. */
  47. public class FacemarkTrain : Facemark
  48. {
  49. protected override void Dispose(bool disposing)
  50. {
  51. try
  52. {
  53. if (disposing)
  54. {
  55. }
  56. if (IsEnabledDispose)
  57. {
  58. if (nativeObj != IntPtr.Zero)
  59. face_FacemarkTrain_delete(nativeObj);
  60. nativeObj = IntPtr.Zero;
  61. }
  62. }
  63. finally
  64. {
  65. base.Dispose(disposing);
  66. }
  67. }
  68. protected internal FacemarkTrain(IntPtr addr) : base(addr) { }
  69. // internal usage only
  70. public static new FacemarkTrain __fromPtr__(IntPtr addr) { return new FacemarkTrain(addr); }
  71. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  72. const string LIBNAME = "__Internal";
  73. #else
  74. const string LIBNAME = "opencvforunity";
  75. #endif
  76. // native support for java finalize()
  77. [DllImport(LIBNAME)]
  78. private static extern void face_FacemarkTrain_delete(IntPtr nativeObj);
  79. }
  80. }