SinusoidalPattern.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. #if !UNITY_WEBGL
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.Structured_lightModule
  8. {
  9. // C++: class SinusoidalPattern
  10. /**
  11. * Class implementing Fourier transform profilometry (FTP) , phase-shifting profilometry (PSP)
  12. * and Fourier-assisted phase-shifting profilometry (FAPS) based on CITE: faps.
  13. *
  14. * This class generates sinusoidal patterns that can be used with FTP, PSP and FAPS.
  15. */
  16. public class SinusoidalPattern : StructuredLightPattern
  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. structured_1light_SinusoidalPattern_delete(nativeObj);
  29. nativeObj = IntPtr.Zero;
  30. }
  31. }
  32. finally
  33. {
  34. base.Dispose(disposing);
  35. }
  36. }
  37. protected internal SinusoidalPattern(IntPtr addr) : base(addr) { }
  38. // internal usage only
  39. public static new SinusoidalPattern __fromPtr__(IntPtr addr) { return new SinusoidalPattern(addr); }
  40. //
  41. // C++: static Ptr_SinusoidalPattern cv::structured_light::SinusoidalPattern::create(Ptr_SinusoidalPattern_Params parameters = makePtr<SinusoidalPattern::Params>())
  42. //
  43. /**
  44. * Constructor.
  45. * param parameters SinusoidalPattern parameters SinusoidalPattern::Params: width, height of the projector and patterns parameters.
  46. *
  47. * return automatically generated
  48. */
  49. public static SinusoidalPattern create(SinusoidalPattern_Params parameters)
  50. {
  51. if (parameters != null) parameters.ThrowIfDisposed();
  52. return SinusoidalPattern.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(structured_1light_SinusoidalPattern_create_10(parameters.getNativeObjAddr())));
  53. }
  54. /**
  55. * Constructor.
  56. *
  57. * return automatically generated
  58. */
  59. public static SinusoidalPattern create()
  60. {
  61. return SinusoidalPattern.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(structured_1light_SinusoidalPattern_create_11()));
  62. }
  63. //
  64. // C++: void cv::structured_light::SinusoidalPattern::computePhaseMap(vector_Mat patternImages, Mat& wrappedPhaseMap, Mat& shadowMask = Mat(), Mat fundamental = Mat())
  65. //
  66. /**
  67. * Compute a wrapped phase map from sinusoidal patterns.
  68. * param patternImages Input data to compute the wrapped phase map.
  69. * param wrappedPhaseMap Wrapped phase map obtained through one of the three methods.
  70. * param shadowMask Mask used to discard shadow regions.
  71. * param fundamental Fundamental matrix used to compute epipolar lines and ease the matching step.
  72. */
  73. public void computePhaseMap(List<Mat> patternImages, Mat wrappedPhaseMap, Mat shadowMask, Mat fundamental)
  74. {
  75. ThrowIfDisposed();
  76. if (wrappedPhaseMap != null) wrappedPhaseMap.ThrowIfDisposed();
  77. if (shadowMask != null) shadowMask.ThrowIfDisposed();
  78. if (fundamental != null) fundamental.ThrowIfDisposed();
  79. Mat patternImages_mat = Converters.vector_Mat_to_Mat(patternImages);
  80. structured_1light_SinusoidalPattern_computePhaseMap_10(nativeObj, patternImages_mat.nativeObj, wrappedPhaseMap.nativeObj, shadowMask.nativeObj, fundamental.nativeObj);
  81. }
  82. /**
  83. * Compute a wrapped phase map from sinusoidal patterns.
  84. * param patternImages Input data to compute the wrapped phase map.
  85. * param wrappedPhaseMap Wrapped phase map obtained through one of the three methods.
  86. * param shadowMask Mask used to discard shadow regions.
  87. */
  88. public void computePhaseMap(List<Mat> patternImages, Mat wrappedPhaseMap, Mat shadowMask)
  89. {
  90. ThrowIfDisposed();
  91. if (wrappedPhaseMap != null) wrappedPhaseMap.ThrowIfDisposed();
  92. if (shadowMask != null) shadowMask.ThrowIfDisposed();
  93. Mat patternImages_mat = Converters.vector_Mat_to_Mat(patternImages);
  94. structured_1light_SinusoidalPattern_computePhaseMap_11(nativeObj, patternImages_mat.nativeObj, wrappedPhaseMap.nativeObj, shadowMask.nativeObj);
  95. }
  96. /**
  97. * Compute a wrapped phase map from sinusoidal patterns.
  98. * param patternImages Input data to compute the wrapped phase map.
  99. * param wrappedPhaseMap Wrapped phase map obtained through one of the three methods.
  100. */
  101. public void computePhaseMap(List<Mat> patternImages, Mat wrappedPhaseMap)
  102. {
  103. ThrowIfDisposed();
  104. if (wrappedPhaseMap != null) wrappedPhaseMap.ThrowIfDisposed();
  105. Mat patternImages_mat = Converters.vector_Mat_to_Mat(patternImages);
  106. structured_1light_SinusoidalPattern_computePhaseMap_12(nativeObj, patternImages_mat.nativeObj, wrappedPhaseMap.nativeObj);
  107. }
  108. //
  109. // C++: void cv::structured_light::SinusoidalPattern::unwrapPhaseMap(Mat wrappedPhaseMap, Mat& unwrappedPhaseMap, Size camSize, Mat shadowMask = Mat())
  110. //
  111. /**
  112. * Unwrap the wrapped phase map to remove phase ambiguities.
  113. * param wrappedPhaseMap The wrapped phase map computed from the pattern.
  114. * param unwrappedPhaseMap The unwrapped phase map used to find correspondences between the two devices.
  115. * param camSize Resolution of the camera.
  116. * param shadowMask Mask used to discard shadow regions.
  117. */
  118. public void unwrapPhaseMap(Mat wrappedPhaseMap, Mat unwrappedPhaseMap, Size camSize, Mat shadowMask)
  119. {
  120. ThrowIfDisposed();
  121. if (wrappedPhaseMap != null) wrappedPhaseMap.ThrowIfDisposed();
  122. if (unwrappedPhaseMap != null) unwrappedPhaseMap.ThrowIfDisposed();
  123. if (shadowMask != null) shadowMask.ThrowIfDisposed();
  124. structured_1light_SinusoidalPattern_unwrapPhaseMap_10(nativeObj, wrappedPhaseMap.nativeObj, unwrappedPhaseMap.nativeObj, camSize.width, camSize.height, shadowMask.nativeObj);
  125. }
  126. /**
  127. * Unwrap the wrapped phase map to remove phase ambiguities.
  128. * param wrappedPhaseMap The wrapped phase map computed from the pattern.
  129. * param unwrappedPhaseMap The unwrapped phase map used to find correspondences between the two devices.
  130. * param camSize Resolution of the camera.
  131. */
  132. public void unwrapPhaseMap(Mat wrappedPhaseMap, Mat unwrappedPhaseMap, Size camSize)
  133. {
  134. ThrowIfDisposed();
  135. if (wrappedPhaseMap != null) wrappedPhaseMap.ThrowIfDisposed();
  136. if (unwrappedPhaseMap != null) unwrappedPhaseMap.ThrowIfDisposed();
  137. structured_1light_SinusoidalPattern_unwrapPhaseMap_11(nativeObj, wrappedPhaseMap.nativeObj, unwrappedPhaseMap.nativeObj, camSize.width, camSize.height);
  138. }
  139. //
  140. // C++: void cv::structured_light::SinusoidalPattern::findProCamMatches(Mat projUnwrappedPhaseMap, Mat camUnwrappedPhaseMap, vector_Mat& matches)
  141. //
  142. /**
  143. * Find correspondences between the two devices thanks to unwrapped phase maps.
  144. * param projUnwrappedPhaseMap Projector's unwrapped phase map.
  145. * param camUnwrappedPhaseMap Camera's unwrapped phase map.
  146. * param matches Images used to display correspondences map.
  147. */
  148. public void findProCamMatches(Mat projUnwrappedPhaseMap, Mat camUnwrappedPhaseMap, List<Mat> matches)
  149. {
  150. ThrowIfDisposed();
  151. if (projUnwrappedPhaseMap != null) projUnwrappedPhaseMap.ThrowIfDisposed();
  152. if (camUnwrappedPhaseMap != null) camUnwrappedPhaseMap.ThrowIfDisposed();
  153. Mat matches_mat = new Mat();
  154. structured_1light_SinusoidalPattern_findProCamMatches_10(nativeObj, projUnwrappedPhaseMap.nativeObj, camUnwrappedPhaseMap.nativeObj, matches_mat.nativeObj);
  155. Converters.Mat_to_vector_Mat(matches_mat, matches);
  156. matches_mat.release();
  157. }
  158. //
  159. // C++: void cv::structured_light::SinusoidalPattern::computeDataModulationTerm(vector_Mat patternImages, Mat& dataModulationTerm, Mat shadowMask)
  160. //
  161. /**
  162. * compute the data modulation term.
  163. * param patternImages captured images with projected patterns.
  164. * param dataModulationTerm Mat where the data modulation term is saved.
  165. * param shadowMask Mask used to discard shadow regions.
  166. */
  167. public void computeDataModulationTerm(List<Mat> patternImages, Mat dataModulationTerm, Mat shadowMask)
  168. {
  169. ThrowIfDisposed();
  170. if (dataModulationTerm != null) dataModulationTerm.ThrowIfDisposed();
  171. if (shadowMask != null) shadowMask.ThrowIfDisposed();
  172. Mat patternImages_mat = Converters.vector_Mat_to_Mat(patternImages);
  173. structured_1light_SinusoidalPattern_computeDataModulationTerm_10(nativeObj, patternImages_mat.nativeObj, dataModulationTerm.nativeObj, shadowMask.nativeObj);
  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++: static Ptr_SinusoidalPattern cv::structured_light::SinusoidalPattern::create(Ptr_SinusoidalPattern_Params parameters = makePtr<SinusoidalPattern::Params>())
  181. [DllImport(LIBNAME)]
  182. private static extern IntPtr structured_1light_SinusoidalPattern_create_10(IntPtr parameters_nativeObj);
  183. [DllImport(LIBNAME)]
  184. private static extern IntPtr structured_1light_SinusoidalPattern_create_11();
  185. // C++: void cv::structured_light::SinusoidalPattern::computePhaseMap(vector_Mat patternImages, Mat& wrappedPhaseMap, Mat& shadowMask = Mat(), Mat fundamental = Mat())
  186. [DllImport(LIBNAME)]
  187. private static extern void structured_1light_SinusoidalPattern_computePhaseMap_10(IntPtr nativeObj, IntPtr patternImages_mat_nativeObj, IntPtr wrappedPhaseMap_nativeObj, IntPtr shadowMask_nativeObj, IntPtr fundamental_nativeObj);
  188. [DllImport(LIBNAME)]
  189. private static extern void structured_1light_SinusoidalPattern_computePhaseMap_11(IntPtr nativeObj, IntPtr patternImages_mat_nativeObj, IntPtr wrappedPhaseMap_nativeObj, IntPtr shadowMask_nativeObj);
  190. [DllImport(LIBNAME)]
  191. private static extern void structured_1light_SinusoidalPattern_computePhaseMap_12(IntPtr nativeObj, IntPtr patternImages_mat_nativeObj, IntPtr wrappedPhaseMap_nativeObj);
  192. // C++: void cv::structured_light::SinusoidalPattern::unwrapPhaseMap(Mat wrappedPhaseMap, Mat& unwrappedPhaseMap, Size camSize, Mat shadowMask = Mat())
  193. [DllImport(LIBNAME)]
  194. private static extern void structured_1light_SinusoidalPattern_unwrapPhaseMap_10(IntPtr nativeObj, IntPtr wrappedPhaseMap_nativeObj, IntPtr unwrappedPhaseMap_nativeObj, double camSize_width, double camSize_height, IntPtr shadowMask_nativeObj);
  195. [DllImport(LIBNAME)]
  196. private static extern void structured_1light_SinusoidalPattern_unwrapPhaseMap_11(IntPtr nativeObj, IntPtr wrappedPhaseMap_nativeObj, IntPtr unwrappedPhaseMap_nativeObj, double camSize_width, double camSize_height);
  197. // C++: void cv::structured_light::SinusoidalPattern::findProCamMatches(Mat projUnwrappedPhaseMap, Mat camUnwrappedPhaseMap, vector_Mat& matches)
  198. [DllImport(LIBNAME)]
  199. private static extern void structured_1light_SinusoidalPattern_findProCamMatches_10(IntPtr nativeObj, IntPtr projUnwrappedPhaseMap_nativeObj, IntPtr camUnwrappedPhaseMap_nativeObj, IntPtr matches_mat_nativeObj);
  200. // C++: void cv::structured_light::SinusoidalPattern::computeDataModulationTerm(vector_Mat patternImages, Mat& dataModulationTerm, Mat shadowMask)
  201. [DllImport(LIBNAME)]
  202. private static extern void structured_1light_SinusoidalPattern_computeDataModulationTerm_10(IntPtr nativeObj, IntPtr patternImages_mat_nativeObj, IntPtr dataModulationTerm_nativeObj, IntPtr shadowMask_nativeObj);
  203. // native support for java finalize()
  204. [DllImport(LIBNAME)]
  205. private static extern void structured_1light_SinusoidalPattern_delete(IntPtr nativeObj);
  206. }
  207. }
  208. #endif