Layer.cs 6.7 KB

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