NormalBayesClassifier.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.MlModule
  7. {
  8. // C++: class NormalBayesClassifier
  9. /**
  10. * Bayes classifier for normally distributed data.
  11. *
  12. * SEE: REF: ml_intro_bayes
  13. */
  14. public class NormalBayesClassifier : StatModel
  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. ml_NormalBayesClassifier_delete(nativeObj);
  27. nativeObj = IntPtr.Zero;
  28. }
  29. }
  30. finally
  31. {
  32. base.Dispose(disposing);
  33. }
  34. }
  35. protected internal NormalBayesClassifier(IntPtr addr) : base(addr) { }
  36. // internal usage only
  37. public static new NormalBayesClassifier __fromPtr__(IntPtr addr) { return new NormalBayesClassifier(addr); }
  38. //
  39. // C++: float cv::ml::NormalBayesClassifier::predictProb(Mat inputs, Mat& outputs, Mat& outputProbs, int flags = 0)
  40. //
  41. /**
  42. * Predicts the response for sample(s).
  43. *
  44. * The method estimates the most probable classes for input vectors. Input vectors (one or more)
  45. * are stored as rows of the matrix inputs. In case of multiple input vectors, there should be one
  46. * output vector outputs. The predicted class for a single input vector is returned by the method.
  47. * The vector outputProbs contains the output probabilities corresponding to each element of
  48. * result.
  49. * param inputs automatically generated
  50. * param outputs automatically generated
  51. * param outputProbs automatically generated
  52. * param flags automatically generated
  53. * return automatically generated
  54. */
  55. public float predictProb(Mat inputs, Mat outputs, Mat outputProbs, int flags)
  56. {
  57. ThrowIfDisposed();
  58. if (inputs != null) inputs.ThrowIfDisposed();
  59. if (outputs != null) outputs.ThrowIfDisposed();
  60. if (outputProbs != null) outputProbs.ThrowIfDisposed();
  61. return ml_NormalBayesClassifier_predictProb_10(nativeObj, inputs.nativeObj, outputs.nativeObj, outputProbs.nativeObj, flags);
  62. }
  63. /**
  64. * Predicts the response for sample(s).
  65. *
  66. * The method estimates the most probable classes for input vectors. Input vectors (one or more)
  67. * are stored as rows of the matrix inputs. In case of multiple input vectors, there should be one
  68. * output vector outputs. The predicted class for a single input vector is returned by the method.
  69. * The vector outputProbs contains the output probabilities corresponding to each element of
  70. * result.
  71. * param inputs automatically generated
  72. * param outputs automatically generated
  73. * param outputProbs automatically generated
  74. * return automatically generated
  75. */
  76. public float predictProb(Mat inputs, Mat outputs, Mat outputProbs)
  77. {
  78. ThrowIfDisposed();
  79. if (inputs != null) inputs.ThrowIfDisposed();
  80. if (outputs != null) outputs.ThrowIfDisposed();
  81. if (outputProbs != null) outputProbs.ThrowIfDisposed();
  82. return ml_NormalBayesClassifier_predictProb_11(nativeObj, inputs.nativeObj, outputs.nativeObj, outputProbs.nativeObj);
  83. }
  84. //
  85. // C++: static Ptr_NormalBayesClassifier cv::ml::NormalBayesClassifier::create()
  86. //
  87. /**
  88. * Creates empty model
  89. * Use StatModel::train to train the model after creation.
  90. * return automatically generated
  91. */
  92. public static NormalBayesClassifier create()
  93. {
  94. return NormalBayesClassifier.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_NormalBayesClassifier_create_10()));
  95. }
  96. //
  97. // C++: static Ptr_NormalBayesClassifier cv::ml::NormalBayesClassifier::load(String filepath, String nodeName = String())
  98. //
  99. /**
  100. * Loads and creates a serialized NormalBayesClassifier from a file
  101. *
  102. * Use NormalBayesClassifier::save to serialize and store an NormalBayesClassifier to disk.
  103. * Load the NormalBayesClassifier from this file again, by calling this function with the path to the file.
  104. * Optionally specify the node for the file containing the classifier
  105. *
  106. * param filepath path to serialized NormalBayesClassifier
  107. * param nodeName name of node containing the classifier
  108. * return automatically generated
  109. */
  110. public static NormalBayesClassifier load(string filepath, string nodeName)
  111. {
  112. return NormalBayesClassifier.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_NormalBayesClassifier_load_10(filepath, nodeName)));
  113. }
  114. /**
  115. * Loads and creates a serialized NormalBayesClassifier from a file
  116. *
  117. * Use NormalBayesClassifier::save to serialize and store an NormalBayesClassifier to disk.
  118. * Load the NormalBayesClassifier from this file again, by calling this function with the path to the file.
  119. * Optionally specify the node for the file containing the classifier
  120. *
  121. * param filepath path to serialized NormalBayesClassifier
  122. * return automatically generated
  123. */
  124. public static NormalBayesClassifier load(string filepath)
  125. {
  126. return NormalBayesClassifier.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(ml_NormalBayesClassifier_load_11(filepath)));
  127. }
  128. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  129. const string LIBNAME = "__Internal";
  130. #else
  131. const string LIBNAME = "opencvforunity";
  132. #endif
  133. // C++: float cv::ml::NormalBayesClassifier::predictProb(Mat inputs, Mat& outputs, Mat& outputProbs, int flags = 0)
  134. [DllImport(LIBNAME)]
  135. private static extern float ml_NormalBayesClassifier_predictProb_10(IntPtr nativeObj, IntPtr inputs_nativeObj, IntPtr outputs_nativeObj, IntPtr outputProbs_nativeObj, int flags);
  136. [DllImport(LIBNAME)]
  137. private static extern float ml_NormalBayesClassifier_predictProb_11(IntPtr nativeObj, IntPtr inputs_nativeObj, IntPtr outputs_nativeObj, IntPtr outputProbs_nativeObj);
  138. // C++: static Ptr_NormalBayesClassifier cv::ml::NormalBayesClassifier::create()
  139. [DllImport(LIBNAME)]
  140. private static extern IntPtr ml_NormalBayesClassifier_create_10();
  141. // C++: static Ptr_NormalBayesClassifier cv::ml::NormalBayesClassifier::load(String filepath, String nodeName = String())
  142. [DllImport(LIBNAME)]
  143. private static extern IntPtr ml_NormalBayesClassifier_load_10(string filepath, string nodeName);
  144. [DllImport(LIBNAME)]
  145. private static extern IntPtr ml_NormalBayesClassifier_load_11(string filepath);
  146. // native support for java finalize()
  147. [DllImport(LIBNAME)]
  148. private static extern void ml_NormalBayesClassifier_delete(IntPtr nativeObj);
  149. }
  150. }