Features2d.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. 
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.Features2dModule
  8. {
  9. // C++: class Features2d
  10. //javadoc: Features2d
  11. public class Features2d
  12. {
  13. //
  14. // C++: void cv::drawKeypoints(Mat image, vector_KeyPoint keypoints, Mat& outImage, Scalar color = Scalar::all(-1), DrawMatchesFlags flags = DrawMatchesFlags::DEFAULT)
  15. //
  16. //javadoc: drawKeypoints(image, keypoints, outImage, color)
  17. public static void drawKeypoints (Mat image, MatOfKeyPoint keypoints, Mat outImage, Scalar color)
  18. {
  19. if (image != null) image.ThrowIfDisposed ();
  20. if (keypoints != null) keypoints.ThrowIfDisposed ();
  21. if (outImage != null) outImage.ThrowIfDisposed ();
  22. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  23. Mat keypoints_mat = keypoints;
  24. features2d_Features2d_drawKeypoints_10(image.nativeObj, keypoints_mat.nativeObj, outImage.nativeObj, color.val[0], color.val[1], color.val[2], color.val[3]);
  25. return;
  26. #else
  27. return;
  28. #endif
  29. }
  30. //javadoc: drawKeypoints(image, keypoints, outImage)
  31. public static void drawKeypoints (Mat image, MatOfKeyPoint keypoints, Mat outImage)
  32. {
  33. if (image != null) image.ThrowIfDisposed ();
  34. if (keypoints != null) keypoints.ThrowIfDisposed ();
  35. if (outImage != null) outImage.ThrowIfDisposed ();
  36. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  37. Mat keypoints_mat = keypoints;
  38. features2d_Features2d_drawKeypoints_12(image.nativeObj, keypoints_mat.nativeObj, outImage.nativeObj);
  39. return;
  40. #else
  41. return;
  42. #endif
  43. }
  44. //
  45. // C++: void cv::drawMatches(Mat img1, vector_KeyPoint keypoints1, Mat img2, vector_KeyPoint keypoints2, vector_DMatch matches1to2, Mat& outImg, Scalar matchColor = Scalar::all(-1), Scalar singlePointColor = Scalar::all(-1), vector_char matchesMask = std::vector<char>(), DrawMatchesFlags flags = DrawMatchesFlags::DEFAULT)
  46. //
  47. //javadoc: drawMatches(img1, keypoints1, img2, keypoints2, matches1to2, outImg, matchColor, singlePointColor, matchesMask)
  48. public static void drawMatches (Mat img1, MatOfKeyPoint keypoints1, Mat img2, MatOfKeyPoint keypoints2, MatOfDMatch matches1to2, Mat outImg, Scalar matchColor, Scalar singlePointColor, MatOfByte matchesMask)
  49. {
  50. if (img1 != null) img1.ThrowIfDisposed ();
  51. if (keypoints1 != null) keypoints1.ThrowIfDisposed ();
  52. if (img2 != null) img2.ThrowIfDisposed ();
  53. if (keypoints2 != null) keypoints2.ThrowIfDisposed ();
  54. if (matches1to2 != null) matches1to2.ThrowIfDisposed ();
  55. if (outImg != null) outImg.ThrowIfDisposed ();
  56. if (matchesMask != null) matchesMask.ThrowIfDisposed ();
  57. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  58. Mat keypoints1_mat = keypoints1;
  59. Mat keypoints2_mat = keypoints2;
  60. Mat matches1to2_mat = matches1to2;
  61. Mat matchesMask_mat = matchesMask;
  62. features2d_Features2d_drawMatches_10(img1.nativeObj, keypoints1_mat.nativeObj, img2.nativeObj, keypoints2_mat.nativeObj, matches1to2_mat.nativeObj, outImg.nativeObj, matchColor.val[0], matchColor.val[1], matchColor.val[2], matchColor.val[3], singlePointColor.val[0], singlePointColor.val[1], singlePointColor.val[2], singlePointColor.val[3], matchesMask_mat.nativeObj);
  63. return;
  64. #else
  65. return;
  66. #endif
  67. }
  68. //javadoc: drawMatches(img1, keypoints1, img2, keypoints2, matches1to2, outImg, matchColor, singlePointColor)
  69. public static void drawMatches (Mat img1, MatOfKeyPoint keypoints1, Mat img2, MatOfKeyPoint keypoints2, MatOfDMatch matches1to2, Mat outImg, Scalar matchColor, Scalar singlePointColor)
  70. {
  71. if (img1 != null) img1.ThrowIfDisposed ();
  72. if (keypoints1 != null) keypoints1.ThrowIfDisposed ();
  73. if (img2 != null) img2.ThrowIfDisposed ();
  74. if (keypoints2 != null) keypoints2.ThrowIfDisposed ();
  75. if (matches1to2 != null) matches1to2.ThrowIfDisposed ();
  76. if (outImg != null) outImg.ThrowIfDisposed ();
  77. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  78. Mat keypoints1_mat = keypoints1;
  79. Mat keypoints2_mat = keypoints2;
  80. Mat matches1to2_mat = matches1to2;
  81. features2d_Features2d_drawMatches_12(img1.nativeObj, keypoints1_mat.nativeObj, img2.nativeObj, keypoints2_mat.nativeObj, matches1to2_mat.nativeObj, outImg.nativeObj, matchColor.val[0], matchColor.val[1], matchColor.val[2], matchColor.val[3], singlePointColor.val[0], singlePointColor.val[1], singlePointColor.val[2], singlePointColor.val[3]);
  82. return;
  83. #else
  84. return;
  85. #endif
  86. }
  87. //javadoc: drawMatches(img1, keypoints1, img2, keypoints2, matches1to2, outImg, matchColor)
  88. public static void drawMatches (Mat img1, MatOfKeyPoint keypoints1, Mat img2, MatOfKeyPoint keypoints2, MatOfDMatch matches1to2, Mat outImg, Scalar matchColor)
  89. {
  90. if (img1 != null) img1.ThrowIfDisposed ();
  91. if (keypoints1 != null) keypoints1.ThrowIfDisposed ();
  92. if (img2 != null) img2.ThrowIfDisposed ();
  93. if (keypoints2 != null) keypoints2.ThrowIfDisposed ();
  94. if (matches1to2 != null) matches1to2.ThrowIfDisposed ();
  95. if (outImg != null) outImg.ThrowIfDisposed ();
  96. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  97. Mat keypoints1_mat = keypoints1;
  98. Mat keypoints2_mat = keypoints2;
  99. Mat matches1to2_mat = matches1to2;
  100. features2d_Features2d_drawMatches_13(img1.nativeObj, keypoints1_mat.nativeObj, img2.nativeObj, keypoints2_mat.nativeObj, matches1to2_mat.nativeObj, outImg.nativeObj, matchColor.val[0], matchColor.val[1], matchColor.val[2], matchColor.val[3]);
  101. return;
  102. #else
  103. return;
  104. #endif
  105. }
  106. //javadoc: drawMatches(img1, keypoints1, img2, keypoints2, matches1to2, outImg)
  107. public static void drawMatches (Mat img1, MatOfKeyPoint keypoints1, Mat img2, MatOfKeyPoint keypoints2, MatOfDMatch matches1to2, Mat outImg)
  108. {
  109. if (img1 != null) img1.ThrowIfDisposed ();
  110. if (keypoints1 != null) keypoints1.ThrowIfDisposed ();
  111. if (img2 != null) img2.ThrowIfDisposed ();
  112. if (keypoints2 != null) keypoints2.ThrowIfDisposed ();
  113. if (matches1to2 != null) matches1to2.ThrowIfDisposed ();
  114. if (outImg != null) outImg.ThrowIfDisposed ();
  115. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  116. Mat keypoints1_mat = keypoints1;
  117. Mat keypoints2_mat = keypoints2;
  118. Mat matches1to2_mat = matches1to2;
  119. features2d_Features2d_drawMatches_14(img1.nativeObj, keypoints1_mat.nativeObj, img2.nativeObj, keypoints2_mat.nativeObj, matches1to2_mat.nativeObj, outImg.nativeObj);
  120. return;
  121. #else
  122. return;
  123. #endif
  124. }
  125. //
  126. // C++: void cv::drawMatches(Mat img1, vector_KeyPoint keypoints1, Mat img2, vector_KeyPoint keypoints2, vector_vector_DMatch matches1to2, Mat& outImg, Scalar matchColor = Scalar::all(-1), Scalar singlePointColor = Scalar::all(-1), vector_vector_char matchesMask = std::vector<std::vector<char> >(), DrawMatchesFlags flags = DrawMatchesFlags::DEFAULT)
  127. //
  128. //javadoc: drawMatchesKnn(img1, keypoints1, img2, keypoints2, matches1to2, outImg, matchColor, singlePointColor, matchesMask)
  129. public static void drawMatchesKnn (Mat img1, MatOfKeyPoint keypoints1, Mat img2, MatOfKeyPoint keypoints2, List<MatOfDMatch> matches1to2, Mat outImg, Scalar matchColor, Scalar singlePointColor, List<MatOfByte> matchesMask)
  130. {
  131. if (img1 != null) img1.ThrowIfDisposed ();
  132. if (keypoints1 != null) keypoints1.ThrowIfDisposed ();
  133. if (img2 != null) img2.ThrowIfDisposed ();
  134. if (keypoints2 != null) keypoints2.ThrowIfDisposed ();
  135. if (outImg != null) outImg.ThrowIfDisposed ();
  136. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  137. Mat keypoints1_mat = keypoints1;
  138. Mat keypoints2_mat = keypoints2;
  139. List<Mat> matches1to2_tmplm = new List<Mat>((matches1to2 != null) ? matches1to2.Count : 0);
  140. Mat matches1to2_mat = Converters.vector_vector_DMatch_to_Mat(matches1to2, matches1to2_tmplm);
  141. List<Mat> matchesMask_tmplm = new List<Mat>((matchesMask != null) ? matchesMask.Count : 0);
  142. Mat matchesMask_mat = Converters.vector_vector_char_to_Mat(matchesMask, matchesMask_tmplm);
  143. features2d_Features2d_drawMatchesKnn_10(img1.nativeObj, keypoints1_mat.nativeObj, img2.nativeObj, keypoints2_mat.nativeObj, matches1to2_mat.nativeObj, outImg.nativeObj, matchColor.val[0], matchColor.val[1], matchColor.val[2], matchColor.val[3], singlePointColor.val[0], singlePointColor.val[1], singlePointColor.val[2], singlePointColor.val[3], matchesMask_mat.nativeObj);
  144. return;
  145. #else
  146. return;
  147. #endif
  148. }
  149. //javadoc: drawMatchesKnn(img1, keypoints1, img2, keypoints2, matches1to2, outImg, matchColor, singlePointColor)
  150. public static void drawMatchesKnn (Mat img1, MatOfKeyPoint keypoints1, Mat img2, MatOfKeyPoint keypoints2, List<MatOfDMatch> matches1to2, Mat outImg, Scalar matchColor, Scalar singlePointColor)
  151. {
  152. if (img1 != null) img1.ThrowIfDisposed ();
  153. if (keypoints1 != null) keypoints1.ThrowIfDisposed ();
  154. if (img2 != null) img2.ThrowIfDisposed ();
  155. if (keypoints2 != null) keypoints2.ThrowIfDisposed ();
  156. if (outImg != null) outImg.ThrowIfDisposed ();
  157. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  158. Mat keypoints1_mat = keypoints1;
  159. Mat keypoints2_mat = keypoints2;
  160. List<Mat> matches1to2_tmplm = new List<Mat>((matches1to2 != null) ? matches1to2.Count : 0);
  161. Mat matches1to2_mat = Converters.vector_vector_DMatch_to_Mat(matches1to2, matches1to2_tmplm);
  162. features2d_Features2d_drawMatchesKnn_12(img1.nativeObj, keypoints1_mat.nativeObj, img2.nativeObj, keypoints2_mat.nativeObj, matches1to2_mat.nativeObj, outImg.nativeObj, matchColor.val[0], matchColor.val[1], matchColor.val[2], matchColor.val[3], singlePointColor.val[0], singlePointColor.val[1], singlePointColor.val[2], singlePointColor.val[3]);
  163. return;
  164. #else
  165. return;
  166. #endif
  167. }
  168. //javadoc: drawMatchesKnn(img1, keypoints1, img2, keypoints2, matches1to2, outImg, matchColor)
  169. public static void drawMatchesKnn (Mat img1, MatOfKeyPoint keypoints1, Mat img2, MatOfKeyPoint keypoints2, List<MatOfDMatch> matches1to2, Mat outImg, Scalar matchColor)
  170. {
  171. if (img1 != null) img1.ThrowIfDisposed ();
  172. if (keypoints1 != null) keypoints1.ThrowIfDisposed ();
  173. if (img2 != null) img2.ThrowIfDisposed ();
  174. if (keypoints2 != null) keypoints2.ThrowIfDisposed ();
  175. if (outImg != null) outImg.ThrowIfDisposed ();
  176. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  177. Mat keypoints1_mat = keypoints1;
  178. Mat keypoints2_mat = keypoints2;
  179. List<Mat> matches1to2_tmplm = new List<Mat>((matches1to2 != null) ? matches1to2.Count : 0);
  180. Mat matches1to2_mat = Converters.vector_vector_DMatch_to_Mat(matches1to2, matches1to2_tmplm);
  181. features2d_Features2d_drawMatchesKnn_13(img1.nativeObj, keypoints1_mat.nativeObj, img2.nativeObj, keypoints2_mat.nativeObj, matches1to2_mat.nativeObj, outImg.nativeObj, matchColor.val[0], matchColor.val[1], matchColor.val[2], matchColor.val[3]);
  182. return;
  183. #else
  184. return;
  185. #endif
  186. }
  187. //javadoc: drawMatchesKnn(img1, keypoints1, img2, keypoints2, matches1to2, outImg)
  188. public static void drawMatchesKnn (Mat img1, MatOfKeyPoint keypoints1, Mat img2, MatOfKeyPoint keypoints2, List<MatOfDMatch> matches1to2, Mat outImg)
  189. {
  190. if (img1 != null) img1.ThrowIfDisposed ();
  191. if (keypoints1 != null) keypoints1.ThrowIfDisposed ();
  192. if (img2 != null) img2.ThrowIfDisposed ();
  193. if (keypoints2 != null) keypoints2.ThrowIfDisposed ();
  194. if (outImg != null) outImg.ThrowIfDisposed ();
  195. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  196. Mat keypoints1_mat = keypoints1;
  197. Mat keypoints2_mat = keypoints2;
  198. List<Mat> matches1to2_tmplm = new List<Mat>((matches1to2 != null) ? matches1to2.Count : 0);
  199. Mat matches1to2_mat = Converters.vector_vector_DMatch_to_Mat(matches1to2, matches1to2_tmplm);
  200. features2d_Features2d_drawMatchesKnn_14(img1.nativeObj, keypoints1_mat.nativeObj, img2.nativeObj, keypoints2_mat.nativeObj, matches1to2_mat.nativeObj, outImg.nativeObj);
  201. return;
  202. #else
  203. return;
  204. #endif
  205. }
  206. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  207. const string LIBNAME = "__Internal";
  208. #else
  209. const string LIBNAME = "opencvforunity";
  210. #endif
  211. // C++: void cv::drawKeypoints(Mat image, vector_KeyPoint keypoints, Mat& outImage, Scalar color = Scalar::all(-1), DrawMatchesFlags flags = DrawMatchesFlags::DEFAULT)
  212. [DllImport (LIBNAME)]
  213. private static extern void features2d_Features2d_drawKeypoints_10 (IntPtr image_nativeObj, IntPtr keypoints_mat_nativeObj, IntPtr outImage_nativeObj, double color_val0, double color_val1, double color_val2, double color_val3);
  214. [DllImport (LIBNAME)]
  215. private static extern void features2d_Features2d_drawKeypoints_12 (IntPtr image_nativeObj, IntPtr keypoints_mat_nativeObj, IntPtr outImage_nativeObj);
  216. // C++: void cv::drawMatches(Mat img1, vector_KeyPoint keypoints1, Mat img2, vector_KeyPoint keypoints2, vector_DMatch matches1to2, Mat& outImg, Scalar matchColor = Scalar::all(-1), Scalar singlePointColor = Scalar::all(-1), vector_char matchesMask = std::vector<char>(), DrawMatchesFlags flags = DrawMatchesFlags::DEFAULT)
  217. [DllImport (LIBNAME)]
  218. private static extern void features2d_Features2d_drawMatches_10 (IntPtr img1_nativeObj, IntPtr keypoints1_mat_nativeObj, IntPtr img2_nativeObj, IntPtr keypoints2_mat_nativeObj, IntPtr matches1to2_mat_nativeObj, IntPtr outImg_nativeObj, double matchColor_val0, double matchColor_val1, double matchColor_val2, double matchColor_val3, double singlePointColor_val0, double singlePointColor_val1, double singlePointColor_val2, double singlePointColor_val3, IntPtr matchesMask_mat_nativeObj);
  219. [DllImport (LIBNAME)]
  220. private static extern void features2d_Features2d_drawMatches_12 (IntPtr img1_nativeObj, IntPtr keypoints1_mat_nativeObj, IntPtr img2_nativeObj, IntPtr keypoints2_mat_nativeObj, IntPtr matches1to2_mat_nativeObj, IntPtr outImg_nativeObj, double matchColor_val0, double matchColor_val1, double matchColor_val2, double matchColor_val3, double singlePointColor_val0, double singlePointColor_val1, double singlePointColor_val2, double singlePointColor_val3);
  221. [DllImport (LIBNAME)]
  222. private static extern void features2d_Features2d_drawMatches_13 (IntPtr img1_nativeObj, IntPtr keypoints1_mat_nativeObj, IntPtr img2_nativeObj, IntPtr keypoints2_mat_nativeObj, IntPtr matches1to2_mat_nativeObj, IntPtr outImg_nativeObj, double matchColor_val0, double matchColor_val1, double matchColor_val2, double matchColor_val3);
  223. [DllImport (LIBNAME)]
  224. private static extern void features2d_Features2d_drawMatches_14 (IntPtr img1_nativeObj, IntPtr keypoints1_mat_nativeObj, IntPtr img2_nativeObj, IntPtr keypoints2_mat_nativeObj, IntPtr matches1to2_mat_nativeObj, IntPtr outImg_nativeObj);
  225. // C++: void cv::drawMatches(Mat img1, vector_KeyPoint keypoints1, Mat img2, vector_KeyPoint keypoints2, vector_vector_DMatch matches1to2, Mat& outImg, Scalar matchColor = Scalar::all(-1), Scalar singlePointColor = Scalar::all(-1), vector_vector_char matchesMask = std::vector<std::vector<char> >(), DrawMatchesFlags flags = DrawMatchesFlags::DEFAULT)
  226. [DllImport (LIBNAME)]
  227. private static extern void features2d_Features2d_drawMatchesKnn_10 (IntPtr img1_nativeObj, IntPtr keypoints1_mat_nativeObj, IntPtr img2_nativeObj, IntPtr keypoints2_mat_nativeObj, IntPtr matches1to2_mat_nativeObj, IntPtr outImg_nativeObj, double matchColor_val0, double matchColor_val1, double matchColor_val2, double matchColor_val3, double singlePointColor_val0, double singlePointColor_val1, double singlePointColor_val2, double singlePointColor_val3, IntPtr matchesMask_mat_nativeObj);
  228. [DllImport (LIBNAME)]
  229. private static extern void features2d_Features2d_drawMatchesKnn_12 (IntPtr img1_nativeObj, IntPtr keypoints1_mat_nativeObj, IntPtr img2_nativeObj, IntPtr keypoints2_mat_nativeObj, IntPtr matches1to2_mat_nativeObj, IntPtr outImg_nativeObj, double matchColor_val0, double matchColor_val1, double matchColor_val2, double matchColor_val3, double singlePointColor_val0, double singlePointColor_val1, double singlePointColor_val2, double singlePointColor_val3);
  230. [DllImport (LIBNAME)]
  231. private static extern void features2d_Features2d_drawMatchesKnn_13 (IntPtr img1_nativeObj, IntPtr keypoints1_mat_nativeObj, IntPtr img2_nativeObj, IntPtr keypoints2_mat_nativeObj, IntPtr matches1to2_mat_nativeObj, IntPtr outImg_nativeObj, double matchColor_val0, double matchColor_val1, double matchColor_val2, double matchColor_val3);
  232. [DllImport (LIBNAME)]
  233. private static extern void features2d_Features2d_drawMatchesKnn_14 (IntPtr img1_nativeObj, IntPtr keypoints1_mat_nativeObj, IntPtr img2_nativeObj, IntPtr keypoints2_mat_nativeObj, IntPtr matches1to2_mat_nativeObj, IntPtr outImg_nativeObj);
  234. }
  235. }