Layer.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 Layer
  10. //javadoc: Layer
  11. public class Layer : Algorithm
  12. {
  13. protected override void Dispose (bool disposing)
  14. {
  15. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  16. try {
  17. if (disposing) {
  18. }
  19. if (IsEnabledDispose) {
  20. if (nativeObj != IntPtr.Zero)
  21. dnn_Layer_delete (nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. } finally {
  25. base.Dispose (disposing);
  26. }
  27. #else
  28. return;
  29. #endif
  30. }
  31. protected internal Layer (IntPtr addr)
  32. : base (addr)
  33. {
  34. }
  35. // internal usage only
  36. public static new Layer __fromPtr__ (IntPtr addr)
  37. {
  38. return new Layer (addr);
  39. }
  40. //
  41. // C++: int cv::dnn::Layer::outputNameToIndex(String outputName)
  42. //
  43. //javadoc: Layer::outputNameToIndex(outputName)
  44. public int outputNameToIndex (string outputName)
  45. {
  46. ThrowIfDisposed ();
  47. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  48. int retVal = dnn_Layer_outputNameToIndex_10 (nativeObj, outputName);
  49. return retVal;
  50. #else
  51. return -1;
  52. #endif
  53. }
  54. //
  55. // C++: void cv::dnn::Layer::finalize(vector_Mat inputs, vector_Mat& outputs)
  56. //
  57. //javadoc: Layer::finalize(inputs, outputs)
  58. public void finalize (List<Mat> inputs, List<Mat> outputs)
  59. {
  60. ThrowIfDisposed ();
  61. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  62. Mat inputs_mat = Converters.vector_Mat_to_Mat (inputs);
  63. Mat outputs_mat = new Mat ();
  64. dnn_Layer_finalize_10 (nativeObj, inputs_mat.nativeObj, outputs_mat.nativeObj);
  65. Converters.Mat_to_vector_Mat (outputs_mat, outputs);
  66. outputs_mat.release ();
  67. return;
  68. #else
  69. return;
  70. #endif
  71. }
  72. //
  73. // C++: void cv::dnn::Layer::run(vector_Mat inputs, vector_Mat& outputs, vector_Mat& internals)
  74. //
  75. //javadoc: Layer::run(inputs, outputs, internals)
  76. [Obsolete ("This method is deprecated.")]
  77. public void run (List<Mat> inputs, List<Mat> outputs, List<Mat> internals)
  78. {
  79. ThrowIfDisposed ();
  80. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  81. Mat inputs_mat = Converters.vector_Mat_to_Mat (inputs);
  82. Mat outputs_mat = new Mat ();
  83. Mat internals_mat = Converters.vector_Mat_to_Mat (internals);
  84. dnn_Layer_run_10 (nativeObj, inputs_mat.nativeObj, outputs_mat.nativeObj, internals_mat.nativeObj);
  85. Converters.Mat_to_vector_Mat (outputs_mat, outputs);
  86. outputs_mat.release ();
  87. Converters.Mat_to_vector_Mat (internals_mat, internals);
  88. internals_mat.release ();
  89. return;
  90. #else
  91. return;
  92. #endif
  93. }
  94. //
  95. // C++: vector_Mat Layer::blobs
  96. //
  97. //javadoc: Layer::get_blobs()
  98. public List<Mat> get_blobs ()
  99. {
  100. ThrowIfDisposed ();
  101. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  102. List<Mat> retVal = new List<Mat> ();
  103. Mat retValMat = new Mat (dnn_Layer_get_1blobs_10 (nativeObj));
  104. Converters.Mat_to_vector_Mat (retValMat, retVal);
  105. return retVal;
  106. #else
  107. return null;
  108. #endif
  109. }
  110. //
  111. // C++: void Layer::blobs
  112. //
  113. //javadoc: Layer::set_blobs(blobs)
  114. public void set_blobs (List<Mat> blobs)
  115. {
  116. ThrowIfDisposed ();
  117. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  118. Mat blobs_mat = Converters.vector_Mat_to_Mat (blobs);
  119. dnn_Layer_set_1blobs_10 (nativeObj, blobs_mat.nativeObj);
  120. return;
  121. #else
  122. return;
  123. #endif
  124. }
  125. //
  126. // C++: String Layer::name
  127. //
  128. //javadoc: Layer::get_name()
  129. public string get_name ()
  130. {
  131. ThrowIfDisposed ();
  132. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  133. string retVal = Marshal.PtrToStringAnsi (dnn_Layer_get_1name_10 (nativeObj));
  134. return retVal;
  135. #else
  136. return null;
  137. #endif
  138. }
  139. //
  140. // C++: String Layer::type
  141. //
  142. //javadoc: Layer::get_type()
  143. public string get_type ()
  144. {
  145. ThrowIfDisposed ();
  146. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  147. string retVal = Marshal.PtrToStringAnsi (dnn_Layer_get_1type_10 (nativeObj));
  148. return retVal;
  149. #else
  150. return null;
  151. #endif
  152. }
  153. //
  154. // C++: int Layer::preferableTarget
  155. //
  156. //javadoc: Layer::get_preferableTarget()
  157. public int get_preferableTarget ()
  158. {
  159. ThrowIfDisposed ();
  160. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  161. int retVal = dnn_Layer_get_1preferableTarget_10 (nativeObj);
  162. return retVal;
  163. #else
  164. return -1;
  165. #endif
  166. }
  167. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  168. const string LIBNAME = "__Internal";
  169. #else
  170. const string LIBNAME = "opencvforunity";
  171. #endif
  172. // C++: int cv::dnn::Layer::outputNameToIndex(String outputName)
  173. [DllImport (LIBNAME)]
  174. private static extern int dnn_Layer_outputNameToIndex_10 (IntPtr nativeObj, string outputName);
  175. // C++: void cv::dnn::Layer::finalize(vector_Mat inputs, vector_Mat& outputs)
  176. [DllImport (LIBNAME)]
  177. private static extern void dnn_Layer_finalize_10 (IntPtr nativeObj, IntPtr inputs_mat_nativeObj, IntPtr outputs_mat_nativeObj);
  178. // C++: void cv::dnn::Layer::run(vector_Mat inputs, vector_Mat& outputs, vector_Mat& internals)
  179. [DllImport (LIBNAME)]
  180. private static extern void dnn_Layer_run_10 (IntPtr nativeObj, IntPtr inputs_mat_nativeObj, IntPtr outputs_mat_nativeObj, IntPtr internals_mat_nativeObj);
  181. // C++: vector_Mat Layer::blobs
  182. [DllImport (LIBNAME)]
  183. private static extern IntPtr dnn_Layer_get_1blobs_10 (IntPtr nativeObj);
  184. // C++: void Layer::blobs
  185. [DllImport (LIBNAME)]
  186. private static extern void dnn_Layer_set_1blobs_10 (IntPtr nativeObj, IntPtr blobs_mat_nativeObj);
  187. // C++: String Layer::name
  188. [DllImport (LIBNAME)]
  189. private static extern IntPtr dnn_Layer_get_1name_10 (IntPtr nativeObj);
  190. // C++: String Layer::type
  191. [DllImport (LIBNAME)]
  192. private static extern IntPtr dnn_Layer_get_1type_10 (IntPtr nativeObj);
  193. // C++: int Layer::preferableTarget
  194. [DllImport (LIBNAME)]
  195. private static extern int dnn_Layer_get_1preferableTarget_10 (IntPtr nativeObj);
  196. // native support for java finalize()
  197. [DllImport (LIBNAME)]
  198. private static extern void dnn_Layer_delete (IntPtr nativeObj);
  199. }
  200. }
  201. #endif