AlignMTB.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.PhotoModule
  7. {
  8. // C++: class AlignMTB
  9. /**
  10. * This algorithm converts images to median threshold bitmaps (1 for pixels brighter than median
  11. * luminance and 0 otherwise) and than aligns the resulting bitmaps using bit operations.
  12. *
  13. * It is invariant to exposure, so exposure values and camera response are not necessary.
  14. *
  15. * In this implementation new image regions are filled with zeros.
  16. *
  17. * For more information see CITE: GW03 .
  18. */
  19. public class AlignMTB : AlignExposures
  20. {
  21. protected override void Dispose(bool disposing)
  22. {
  23. try
  24. {
  25. if (disposing)
  26. {
  27. }
  28. if (IsEnabledDispose)
  29. {
  30. if (nativeObj != IntPtr.Zero)
  31. photo_AlignMTB_delete(nativeObj);
  32. nativeObj = IntPtr.Zero;
  33. }
  34. }
  35. finally
  36. {
  37. base.Dispose(disposing);
  38. }
  39. }
  40. protected internal AlignMTB(IntPtr addr) : base(addr) { }
  41. // internal usage only
  42. public static new AlignMTB __fromPtr__(IntPtr addr) { return new AlignMTB(addr); }
  43. //
  44. // C++: void cv::AlignMTB::process(vector_Mat src, vector_Mat dst, Mat times, Mat response)
  45. //
  46. public override void process(List<Mat> src, List<Mat> dst, Mat times, Mat response)
  47. {
  48. ThrowIfDisposed();
  49. if (times != null) times.ThrowIfDisposed();
  50. if (response != null) response.ThrowIfDisposed();
  51. Mat src_mat = Converters.vector_Mat_to_Mat(src);
  52. Mat dst_mat = Converters.vector_Mat_to_Mat(dst);
  53. photo_AlignMTB_process_10(nativeObj, src_mat.nativeObj, dst_mat.nativeObj, times.nativeObj, response.nativeObj);
  54. }
  55. //
  56. // C++: void cv::AlignMTB::process(vector_Mat src, vector_Mat dst)
  57. //
  58. /**
  59. * Short version of process, that doesn't take extra arguments.
  60. *
  61. * param src vector of input images
  62. * param dst vector of aligned images
  63. */
  64. public void process(List<Mat> src, List<Mat> dst)
  65. {
  66. ThrowIfDisposed();
  67. Mat src_mat = Converters.vector_Mat_to_Mat(src);
  68. Mat dst_mat = Converters.vector_Mat_to_Mat(dst);
  69. photo_AlignMTB_process_11(nativeObj, src_mat.nativeObj, dst_mat.nativeObj);
  70. }
  71. //
  72. // C++: Point cv::AlignMTB::calculateShift(Mat img0, Mat img1)
  73. //
  74. /**
  75. * Calculates shift between two images, i. e. how to shift the second image to correspond it with the
  76. * first.
  77. *
  78. * param img0 first image
  79. * param img1 second image
  80. * return automatically generated
  81. */
  82. public Point calculateShift(Mat img0, Mat img1)
  83. {
  84. ThrowIfDisposed();
  85. if (img0 != null) img0.ThrowIfDisposed();
  86. if (img1 != null) img1.ThrowIfDisposed();
  87. double[] tmpArray = new double[2];
  88. photo_AlignMTB_calculateShift_10(nativeObj, img0.nativeObj, img1.nativeObj, tmpArray);
  89. Point retVal = new Point(tmpArray);
  90. return retVal;
  91. }
  92. //
  93. // C++: void cv::AlignMTB::shiftMat(Mat src, Mat& dst, Point shift)
  94. //
  95. /**
  96. * Helper function, that shift Mat filling new regions with zeros.
  97. *
  98. * param src input image
  99. * param dst result image
  100. * param shift shift value
  101. */
  102. public void shiftMat(Mat src, Mat dst, Point shift)
  103. {
  104. ThrowIfDisposed();
  105. if (src != null) src.ThrowIfDisposed();
  106. if (dst != null) dst.ThrowIfDisposed();
  107. photo_AlignMTB_shiftMat_10(nativeObj, src.nativeObj, dst.nativeObj, shift.x, shift.y);
  108. }
  109. //
  110. // C++: void cv::AlignMTB::computeBitmaps(Mat img, Mat& tb, Mat& eb)
  111. //
  112. /**
  113. * Computes median threshold and exclude bitmaps of given image.
  114. *
  115. * param img input image
  116. * param tb median threshold bitmap
  117. * param eb exclude bitmap
  118. */
  119. public void computeBitmaps(Mat img, Mat tb, Mat eb)
  120. {
  121. ThrowIfDisposed();
  122. if (img != null) img.ThrowIfDisposed();
  123. if (tb != null) tb.ThrowIfDisposed();
  124. if (eb != null) eb.ThrowIfDisposed();
  125. photo_AlignMTB_computeBitmaps_10(nativeObj, img.nativeObj, tb.nativeObj, eb.nativeObj);
  126. }
  127. //
  128. // C++: int cv::AlignMTB::getMaxBits()
  129. //
  130. public int getMaxBits()
  131. {
  132. ThrowIfDisposed();
  133. return photo_AlignMTB_getMaxBits_10(nativeObj);
  134. }
  135. //
  136. // C++: void cv::AlignMTB::setMaxBits(int max_bits)
  137. //
  138. public void setMaxBits(int max_bits)
  139. {
  140. ThrowIfDisposed();
  141. photo_AlignMTB_setMaxBits_10(nativeObj, max_bits);
  142. }
  143. //
  144. // C++: int cv::AlignMTB::getExcludeRange()
  145. //
  146. public int getExcludeRange()
  147. {
  148. ThrowIfDisposed();
  149. return photo_AlignMTB_getExcludeRange_10(nativeObj);
  150. }
  151. //
  152. // C++: void cv::AlignMTB::setExcludeRange(int exclude_range)
  153. //
  154. public void setExcludeRange(int exclude_range)
  155. {
  156. ThrowIfDisposed();
  157. photo_AlignMTB_setExcludeRange_10(nativeObj, exclude_range);
  158. }
  159. //
  160. // C++: bool cv::AlignMTB::getCut()
  161. //
  162. public bool getCut()
  163. {
  164. ThrowIfDisposed();
  165. return photo_AlignMTB_getCut_10(nativeObj);
  166. }
  167. //
  168. // C++: void cv::AlignMTB::setCut(bool value)
  169. //
  170. public void setCut(bool value)
  171. {
  172. ThrowIfDisposed();
  173. photo_AlignMTB_setCut_10(nativeObj, value);
  174. }
  175. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  176. const string LIBNAME = "__Internal";
  177. #else
  178. const string LIBNAME = "opencvforunity";
  179. #endif
  180. // C++: void cv::AlignMTB::process(vector_Mat src, vector_Mat dst, Mat times, Mat response)
  181. [DllImport(LIBNAME)]
  182. private static extern void photo_AlignMTB_process_10(IntPtr nativeObj, IntPtr src_mat_nativeObj, IntPtr dst_mat_nativeObj, IntPtr times_nativeObj, IntPtr response_nativeObj);
  183. // C++: void cv::AlignMTB::process(vector_Mat src, vector_Mat dst)
  184. [DllImport(LIBNAME)]
  185. private static extern void photo_AlignMTB_process_11(IntPtr nativeObj, IntPtr src_mat_nativeObj, IntPtr dst_mat_nativeObj);
  186. // C++: Point cv::AlignMTB::calculateShift(Mat img0, Mat img1)
  187. [DllImport(LIBNAME)]
  188. private static extern void photo_AlignMTB_calculateShift_10(IntPtr nativeObj, IntPtr img0_nativeObj, IntPtr img1_nativeObj, double[] retVal);
  189. // C++: void cv::AlignMTB::shiftMat(Mat src, Mat& dst, Point shift)
  190. [DllImport(LIBNAME)]
  191. private static extern void photo_AlignMTB_shiftMat_10(IntPtr nativeObj, IntPtr src_nativeObj, IntPtr dst_nativeObj, double shift_x, double shift_y);
  192. // C++: void cv::AlignMTB::computeBitmaps(Mat img, Mat& tb, Mat& eb)
  193. [DllImport(LIBNAME)]
  194. private static extern void photo_AlignMTB_computeBitmaps_10(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr tb_nativeObj, IntPtr eb_nativeObj);
  195. // C++: int cv::AlignMTB::getMaxBits()
  196. [DllImport(LIBNAME)]
  197. private static extern int photo_AlignMTB_getMaxBits_10(IntPtr nativeObj);
  198. // C++: void cv::AlignMTB::setMaxBits(int max_bits)
  199. [DllImport(LIBNAME)]
  200. private static extern void photo_AlignMTB_setMaxBits_10(IntPtr nativeObj, int max_bits);
  201. // C++: int cv::AlignMTB::getExcludeRange()
  202. [DllImport(LIBNAME)]
  203. private static extern int photo_AlignMTB_getExcludeRange_10(IntPtr nativeObj);
  204. // C++: void cv::AlignMTB::setExcludeRange(int exclude_range)
  205. [DllImport(LIBNAME)]
  206. private static extern void photo_AlignMTB_setExcludeRange_10(IntPtr nativeObj, int exclude_range);
  207. // C++: bool cv::AlignMTB::getCut()
  208. [DllImport(LIBNAME)]
  209. [return: MarshalAs(UnmanagedType.U1)]
  210. private static extern bool photo_AlignMTB_getCut_10(IntPtr nativeObj);
  211. // C++: void cv::AlignMTB::setCut(bool value)
  212. [DllImport(LIBNAME)]
  213. private static extern void photo_AlignMTB_setCut_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool value);
  214. // native support for java finalize()
  215. [DllImport(LIBNAME)]
  216. private static extern void photo_AlignMTB_delete(IntPtr nativeObj);
  217. }
  218. }