KeypointsModel.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #if !UNITY_WSA_10_0
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.DnnModule
  8. {
  9. // C++: class KeypointsModel
  10. /**
  11. * This class represents high-level API for keypoints models
  12. *
  13. * KeypointsModel allows to set params for preprocessing input image.
  14. * KeypointsModel creates net from file with trained weights and config,
  15. * sets preprocessing input, runs forward pass and returns the x and y coordinates of each detected keypoint
  16. */
  17. public class KeypointsModel : Model
  18. {
  19. protected override void Dispose(bool disposing)
  20. {
  21. try
  22. {
  23. if (disposing)
  24. {
  25. }
  26. if (IsEnabledDispose)
  27. {
  28. if (nativeObj != IntPtr.Zero)
  29. dnn_KeypointsModel_delete(nativeObj);
  30. nativeObj = IntPtr.Zero;
  31. }
  32. }
  33. finally
  34. {
  35. base.Dispose(disposing);
  36. }
  37. }
  38. protected internal KeypointsModel(IntPtr addr) : base(addr) { }
  39. // internal usage only
  40. public static new KeypointsModel __fromPtr__(IntPtr addr) { return new KeypointsModel(addr); }
  41. //
  42. // C++: cv::dnn::KeypointsModel::KeypointsModel(String model, String config = "")
  43. //
  44. /**
  45. * Create keypoints model from network represented in one of the supported formats.
  46. * An order of {code model} and {code config} arguments does not matter.
  47. * param model Binary file contains trained weights.
  48. * param config Text file contains network configuration.
  49. */
  50. public KeypointsModel(string model, string config) :
  51. base(DisposableObject.ThrowIfNullIntPtr(dnn_KeypointsModel_KeypointsModel_10(model, config)))
  52. {
  53. }
  54. /**
  55. * Create keypoints model from network represented in one of the supported formats.
  56. * An order of {code model} and {code config} arguments does not matter.
  57. * param model Binary file contains trained weights.
  58. */
  59. public KeypointsModel(string model) :
  60. base(DisposableObject.ThrowIfNullIntPtr(dnn_KeypointsModel_KeypointsModel_11(model)))
  61. {
  62. }
  63. //
  64. // C++: cv::dnn::KeypointsModel::KeypointsModel(Net network)
  65. //
  66. /**
  67. * Create model from deep learning network.
  68. * param network Net object.
  69. */
  70. public KeypointsModel(Net network) :
  71. base(DisposableObject.ThrowIfNullIntPtr(dnn_KeypointsModel_KeypointsModel_12(network.nativeObj)))
  72. {
  73. }
  74. //
  75. // C++: vector_Point2f cv::dnn::KeypointsModel::estimate(Mat frame, float thresh = 0.5)
  76. //
  77. /**
  78. * Given the {code input} frame, create input blob, run net
  79. * param thresh minimum confidence threshold to select a keypoint
  80. * return a vector holding the x and y coordinates of each detected keypoint
  81. *
  82. * param frame automatically generated
  83. */
  84. public MatOfPoint2f estimate(Mat frame, float thresh)
  85. {
  86. ThrowIfDisposed();
  87. if (frame != null) frame.ThrowIfDisposed();
  88. return MatOfPoint2f.fromNativeAddr(DisposableObject.ThrowIfNullIntPtr(dnn_KeypointsModel_estimate_10(nativeObj, frame.nativeObj, thresh)));
  89. }
  90. /**
  91. * Given the {code input} frame, create input blob, run net
  92. * return a vector holding the x and y coordinates of each detected keypoint
  93. *
  94. * param frame automatically generated
  95. */
  96. public MatOfPoint2f estimate(Mat frame)
  97. {
  98. ThrowIfDisposed();
  99. if (frame != null) frame.ThrowIfDisposed();
  100. return MatOfPoint2f.fromNativeAddr(DisposableObject.ThrowIfNullIntPtr(dnn_KeypointsModel_estimate_11(nativeObj, frame.nativeObj)));
  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++: cv::dnn::KeypointsModel::KeypointsModel(String model, String config = "")
  108. [DllImport(LIBNAME)]
  109. private static extern IntPtr dnn_KeypointsModel_KeypointsModel_10(string model, string config);
  110. [DllImport(LIBNAME)]
  111. private static extern IntPtr dnn_KeypointsModel_KeypointsModel_11(string model);
  112. // C++: cv::dnn::KeypointsModel::KeypointsModel(Net network)
  113. [DllImport(LIBNAME)]
  114. private static extern IntPtr dnn_KeypointsModel_KeypointsModel_12(IntPtr network_nativeObj);
  115. // C++: vector_Point2f cv::dnn::KeypointsModel::estimate(Mat frame, float thresh = 0.5)
  116. [DllImport(LIBNAME)]
  117. private static extern IntPtr dnn_KeypointsModel_estimate_10(IntPtr nativeObj, IntPtr frame_nativeObj, float thresh);
  118. [DllImport(LIBNAME)]
  119. private static extern IntPtr dnn_KeypointsModel_estimate_11(IntPtr nativeObj, IntPtr frame_nativeObj);
  120. // native support for java finalize()
  121. [DllImport(LIBNAME)]
  122. private static extern void dnn_KeypointsModel_delete(IntPtr nativeObj);
  123. }
  124. }
  125. #endif