BFMatcher.cs 7.3 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 BFMatcher
  9. /**
  10. * Brute-force descriptor matcher.
  11. *
  12. * For each descriptor in the first set, this matcher finds the closest descriptor in the second set
  13. * by trying each one. This descriptor matcher supports masking permissible matches of descriptor
  14. * sets.
  15. */
  16. public class BFMatcher : DescriptorMatcher
  17. {
  18. protected override void Dispose(bool disposing)
  19. {
  20. try
  21. {
  22. if (disposing)
  23. {
  24. }
  25. if (IsEnabledDispose)
  26. {
  27. if (nativeObj != IntPtr.Zero)
  28. features2d_BFMatcher_delete(nativeObj);
  29. nativeObj = IntPtr.Zero;
  30. }
  31. }
  32. finally
  33. {
  34. base.Dispose(disposing);
  35. }
  36. }
  37. protected internal BFMatcher(IntPtr addr) : base(addr) { }
  38. // internal usage only
  39. public static new BFMatcher __fromPtr__(IntPtr addr) { return new BFMatcher(addr); }
  40. //
  41. // C++: cv::BFMatcher::BFMatcher(int normType = NORM_L2, bool crossCheck = false)
  42. //
  43. /**
  44. * Brute-force matcher constructor (obsolete). Please use BFMatcher.create()
  45. *
  46. *
  47. * param normType automatically generated
  48. * param crossCheck automatically generated
  49. */
  50. public BFMatcher(int normType, bool crossCheck) :
  51. base(DisposableObject.ThrowIfNullIntPtr(features2d_BFMatcher_BFMatcher_10(normType, crossCheck)))
  52. {
  53. }
  54. /**
  55. * Brute-force matcher constructor (obsolete). Please use BFMatcher.create()
  56. *
  57. *
  58. * param normType automatically generated
  59. */
  60. public BFMatcher(int normType) :
  61. base(DisposableObject.ThrowIfNullIntPtr(features2d_BFMatcher_BFMatcher_11(normType)))
  62. {
  63. }
  64. /**
  65. * Brute-force matcher constructor (obsolete). Please use BFMatcher.create()
  66. *
  67. *
  68. */
  69. public BFMatcher() :
  70. base(DisposableObject.ThrowIfNullIntPtr(features2d_BFMatcher_BFMatcher_12()))
  71. {
  72. }
  73. //
  74. // C++: static Ptr_BFMatcher cv::BFMatcher::create(int normType = NORM_L2, bool crossCheck = false)
  75. //
  76. /**
  77. * Brute-force matcher create method.
  78. * param normType One of NORM_L1, NORM_L2, NORM_HAMMING, NORM_HAMMING2. L1 and L2 norms are
  79. * preferable choices for SIFT and SURF descriptors, NORM_HAMMING should be used with ORB, BRISK and
  80. * BRIEF, NORM_HAMMING2 should be used with ORB when WTA_K==3 or 4 (see ORB::ORB constructor
  81. * description).
  82. * param crossCheck If it is false, this is will be default BFMatcher behaviour when it finds the k
  83. * nearest neighbors for each query descriptor. If crossCheck==true, then the knnMatch() method with
  84. * k=1 will only return pairs (i,j) such that for i-th query descriptor the j-th descriptor in the
  85. * matcher's collection is the nearest and vice versa, i.e. the BFMatcher will only return consistent
  86. * pairs. Such technique usually produces best results with minimal number of outliers when there are
  87. * enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper.
  88. * return automatically generated
  89. */
  90. public static BFMatcher create(int normType, bool crossCheck)
  91. {
  92. return BFMatcher.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(features2d_BFMatcher_create_10(normType, crossCheck)));
  93. }
  94. /**
  95. * Brute-force matcher create method.
  96. * param normType One of NORM_L1, NORM_L2, NORM_HAMMING, NORM_HAMMING2. L1 and L2 norms are
  97. * preferable choices for SIFT and SURF descriptors, NORM_HAMMING should be used with ORB, BRISK and
  98. * BRIEF, NORM_HAMMING2 should be used with ORB when WTA_K==3 or 4 (see ORB::ORB constructor
  99. * description).
  100. * nearest neighbors for each query descriptor. If crossCheck==true, then the knnMatch() method with
  101. * k=1 will only return pairs (i,j) such that for i-th query descriptor the j-th descriptor in the
  102. * matcher's collection is the nearest and vice versa, i.e. the BFMatcher will only return consistent
  103. * pairs. Such technique usually produces best results with minimal number of outliers when there are
  104. * enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper.
  105. * return automatically generated
  106. */
  107. public static new BFMatcher create(int normType)
  108. {
  109. return BFMatcher.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(features2d_BFMatcher_create_11(normType)));
  110. }
  111. /**
  112. * Brute-force matcher create method.
  113. * preferable choices for SIFT and SURF descriptors, NORM_HAMMING should be used with ORB, BRISK and
  114. * BRIEF, NORM_HAMMING2 should be used with ORB when WTA_K==3 or 4 (see ORB::ORB constructor
  115. * description).
  116. * nearest neighbors for each query descriptor. If crossCheck==true, then the knnMatch() method with
  117. * k=1 will only return pairs (i,j) such that for i-th query descriptor the j-th descriptor in the
  118. * matcher's collection is the nearest and vice versa, i.e. the BFMatcher will only return consistent
  119. * pairs. Such technique usually produces best results with minimal number of outliers when there are
  120. * enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper.
  121. * return automatically generated
  122. */
  123. public static BFMatcher create()
  124. {
  125. return BFMatcher.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(features2d_BFMatcher_create_12()));
  126. }
  127. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  128. const string LIBNAME = "__Internal";
  129. #else
  130. const string LIBNAME = "opencvforunity";
  131. #endif
  132. // C++: cv::BFMatcher::BFMatcher(int normType = NORM_L2, bool crossCheck = false)
  133. [DllImport(LIBNAME)]
  134. private static extern IntPtr features2d_BFMatcher_BFMatcher_10(int normType, [MarshalAs(UnmanagedType.U1)] bool crossCheck);
  135. [DllImport(LIBNAME)]
  136. private static extern IntPtr features2d_BFMatcher_BFMatcher_11(int normType);
  137. [DllImport(LIBNAME)]
  138. private static extern IntPtr features2d_BFMatcher_BFMatcher_12();
  139. // C++: static Ptr_BFMatcher cv::BFMatcher::create(int normType = NORM_L2, bool crossCheck = false)
  140. [DllImport(LIBNAME)]
  141. private static extern IntPtr features2d_BFMatcher_create_10(int normType, [MarshalAs(UnmanagedType.U1)] bool crossCheck);
  142. [DllImport(LIBNAME)]
  143. private static extern IntPtr features2d_BFMatcher_create_11(int normType);
  144. [DllImport(LIBNAME)]
  145. private static extern IntPtr features2d_BFMatcher_create_12();
  146. // native support for java finalize()
  147. [DllImport(LIBNAME)]
  148. private static extern void features2d_BFMatcher_delete(IntPtr nativeObj);
  149. }
  150. }