BOWImgDescriptorExtractor.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.Features2dModule
  7. {
  8. // C++: class BOWImgDescriptorExtractor
  9. /**
  10. * Class to compute an image descriptor using the *bag of visual words*.
  11. *
  12. * Such a computation consists of the following steps:
  13. *
  14. * 1. Compute descriptors for a given image and its keypoints set.
  15. * 2. Find the nearest visual words from the vocabulary for each keypoint descriptor.
  16. * 3. Compute the bag-of-words image descriptor as is a normalized histogram of vocabulary words
  17. * encountered in the image. The i-th bin of the histogram is a frequency of i-th word of the
  18. * vocabulary in the given image.
  19. */
  20. public class BOWImgDescriptorExtractor : DisposableOpenCVObject
  21. {
  22. protected override void Dispose(bool disposing)
  23. {
  24. try
  25. {
  26. if (disposing)
  27. {
  28. }
  29. if (IsEnabledDispose)
  30. {
  31. if (nativeObj != IntPtr.Zero)
  32. features2d_BOWImgDescriptorExtractor_delete(nativeObj);
  33. nativeObj = IntPtr.Zero;
  34. }
  35. }
  36. finally
  37. {
  38. base.Dispose(disposing);
  39. }
  40. }
  41. protected internal BOWImgDescriptorExtractor(IntPtr addr) : base(addr) { }
  42. public IntPtr getNativeObjAddr() { return nativeObj; }
  43. // internal usage only
  44. public static BOWImgDescriptorExtractor __fromPtr__(IntPtr addr) { return new BOWImgDescriptorExtractor(addr); }
  45. //
  46. // C++: cv::BOWImgDescriptorExtractor::BOWImgDescriptorExtractor(Ptr_DescriptorExtractor dextractor, Ptr_DescriptorMatcher dmatcher)
  47. //
  48. // Unknown type 'Ptr_DescriptorExtractor' (I), skipping the function
  49. //
  50. // C++: void cv::BOWImgDescriptorExtractor::setVocabulary(Mat vocabulary)
  51. //
  52. /**
  53. * Sets a visual vocabulary.
  54. *
  55. * param vocabulary Vocabulary (can be trained using the inheritor of BOWTrainer ). Each row of the
  56. * vocabulary is a visual word (cluster center).
  57. */
  58. public void setVocabulary(Mat vocabulary)
  59. {
  60. ThrowIfDisposed();
  61. if (vocabulary != null) vocabulary.ThrowIfDisposed();
  62. features2d_BOWImgDescriptorExtractor_setVocabulary_10(nativeObj, vocabulary.nativeObj);
  63. }
  64. //
  65. // C++: Mat cv::BOWImgDescriptorExtractor::getVocabulary()
  66. //
  67. /**
  68. * Returns the set vocabulary.
  69. * return automatically generated
  70. */
  71. public Mat getVocabulary()
  72. {
  73. ThrowIfDisposed();
  74. return new Mat(DisposableObject.ThrowIfNullIntPtr(features2d_BOWImgDescriptorExtractor_getVocabulary_10(nativeObj)));
  75. }
  76. //
  77. // C++: void cv::BOWImgDescriptorExtractor::compute2(Mat image, vector_KeyPoint keypoints, Mat& imgDescriptor)
  78. //
  79. /**
  80. *
  81. * param imgDescriptor Computed output image descriptor.
  82. * pointIdxsOfClusters[i] are keypoint indices that belong to the i -th cluster (word of vocabulary)
  83. * returned if it is non-zero.
  84. * param image automatically generated
  85. * param keypoints automatically generated
  86. */
  87. public void compute(Mat image, MatOfKeyPoint keypoints, Mat imgDescriptor)
  88. {
  89. ThrowIfDisposed();
  90. if (image != null) image.ThrowIfDisposed();
  91. if (keypoints != null) keypoints.ThrowIfDisposed();
  92. if (imgDescriptor != null) imgDescriptor.ThrowIfDisposed();
  93. Mat keypoints_mat = keypoints;
  94. features2d_BOWImgDescriptorExtractor_compute_10(nativeObj, image.nativeObj, keypoints_mat.nativeObj, imgDescriptor.nativeObj);
  95. }
  96. //
  97. // C++: int cv::BOWImgDescriptorExtractor::descriptorSize()
  98. //
  99. /**
  100. * Returns an image descriptor size if the vocabulary is set. Otherwise, it returns 0.
  101. * return automatically generated
  102. */
  103. public int descriptorSize()
  104. {
  105. ThrowIfDisposed();
  106. return features2d_BOWImgDescriptorExtractor_descriptorSize_10(nativeObj);
  107. }
  108. //
  109. // C++: int cv::BOWImgDescriptorExtractor::descriptorType()
  110. //
  111. /**
  112. * Returns an image descriptor type.
  113. * return automatically generated
  114. */
  115. public int descriptorType()
  116. {
  117. ThrowIfDisposed();
  118. return features2d_BOWImgDescriptorExtractor_descriptorType_10(nativeObj);
  119. }
  120. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  121. const string LIBNAME = "__Internal";
  122. #else
  123. const string LIBNAME = "opencvforunity";
  124. #endif
  125. // C++: void cv::BOWImgDescriptorExtractor::setVocabulary(Mat vocabulary)
  126. [DllImport(LIBNAME)]
  127. private static extern void features2d_BOWImgDescriptorExtractor_setVocabulary_10(IntPtr nativeObj, IntPtr vocabulary_nativeObj);
  128. // C++: Mat cv::BOWImgDescriptorExtractor::getVocabulary()
  129. [DllImport(LIBNAME)]
  130. private static extern IntPtr features2d_BOWImgDescriptorExtractor_getVocabulary_10(IntPtr nativeObj);
  131. // C++: void cv::BOWImgDescriptorExtractor::compute2(Mat image, vector_KeyPoint keypoints, Mat& imgDescriptor)
  132. [DllImport(LIBNAME)]
  133. private static extern void features2d_BOWImgDescriptorExtractor_compute_10(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr keypoints_mat_nativeObj, IntPtr imgDescriptor_nativeObj);
  134. // C++: int cv::BOWImgDescriptorExtractor::descriptorSize()
  135. [DllImport(LIBNAME)]
  136. private static extern int features2d_BOWImgDescriptorExtractor_descriptorSize_10(IntPtr nativeObj);
  137. // C++: int cv::BOWImgDescriptorExtractor::descriptorType()
  138. [DllImport(LIBNAME)]
  139. private static extern int features2d_BOWImgDescriptorExtractor_descriptorType_10(IntPtr nativeObj);
  140. // native support for java finalize()
  141. [DllImport(LIBNAME)]
  142. private static extern void features2d_BOWImgDescriptorExtractor_delete(IntPtr nativeObj);
  143. }
  144. }