MergeMertens.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 MergeMertens
  9. /**
  10. * Pixels are weighted using contrast, saturation and well-exposedness measures, than images are
  11. * combined using laplacian pyramids.
  12. *
  13. * The resulting image weight is constructed as weighted average of contrast, saturation and
  14. * well-exposedness measures.
  15. *
  16. * The resulting image doesn't require tonemapping and can be converted to 8-bit image by multiplying
  17. * by 255, but it's recommended to apply gamma correction and/or linear tonemapping.
  18. *
  19. * For more information see CITE: MK07 .
  20. */
  21. public class MergeMertens : MergeExposures
  22. {
  23. protected override void Dispose(bool disposing)
  24. {
  25. try
  26. {
  27. if (disposing)
  28. {
  29. }
  30. if (IsEnabledDispose)
  31. {
  32. if (nativeObj != IntPtr.Zero)
  33. photo_MergeMertens_delete(nativeObj);
  34. nativeObj = IntPtr.Zero;
  35. }
  36. }
  37. finally
  38. {
  39. base.Dispose(disposing);
  40. }
  41. }
  42. protected internal MergeMertens(IntPtr addr) : base(addr) { }
  43. // internal usage only
  44. public static new MergeMertens __fromPtr__(IntPtr addr) { return new MergeMertens(addr); }
  45. //
  46. // C++: void cv::MergeMertens::process(vector_Mat src, Mat& dst, Mat times, Mat response)
  47. //
  48. public override void process(List<Mat> src, Mat dst, Mat times, Mat response)
  49. {
  50. ThrowIfDisposed();
  51. if (dst != null) dst.ThrowIfDisposed();
  52. if (times != null) times.ThrowIfDisposed();
  53. if (response != null) response.ThrowIfDisposed();
  54. Mat src_mat = Converters.vector_Mat_to_Mat(src);
  55. photo_MergeMertens_process_10(nativeObj, src_mat.nativeObj, dst.nativeObj, times.nativeObj, response.nativeObj);
  56. }
  57. //
  58. // C++: void cv::MergeMertens::process(vector_Mat src, Mat& dst)
  59. //
  60. /**
  61. * Short version of process, that doesn't take extra arguments.
  62. *
  63. * param src vector of input images
  64. * param dst result image
  65. */
  66. public void process(List<Mat> src, Mat dst)
  67. {
  68. ThrowIfDisposed();
  69. if (dst != null) dst.ThrowIfDisposed();
  70. Mat src_mat = Converters.vector_Mat_to_Mat(src);
  71. photo_MergeMertens_process_11(nativeObj, src_mat.nativeObj, dst.nativeObj);
  72. }
  73. //
  74. // C++: float cv::MergeMertens::getContrastWeight()
  75. //
  76. public float getContrastWeight()
  77. {
  78. ThrowIfDisposed();
  79. return photo_MergeMertens_getContrastWeight_10(nativeObj);
  80. }
  81. //
  82. // C++: void cv::MergeMertens::setContrastWeight(float contrast_weiht)
  83. //
  84. public void setContrastWeight(float contrast_weiht)
  85. {
  86. ThrowIfDisposed();
  87. photo_MergeMertens_setContrastWeight_10(nativeObj, contrast_weiht);
  88. }
  89. //
  90. // C++: float cv::MergeMertens::getSaturationWeight()
  91. //
  92. public float getSaturationWeight()
  93. {
  94. ThrowIfDisposed();
  95. return photo_MergeMertens_getSaturationWeight_10(nativeObj);
  96. }
  97. //
  98. // C++: void cv::MergeMertens::setSaturationWeight(float saturation_weight)
  99. //
  100. public void setSaturationWeight(float saturation_weight)
  101. {
  102. ThrowIfDisposed();
  103. photo_MergeMertens_setSaturationWeight_10(nativeObj, saturation_weight);
  104. }
  105. //
  106. // C++: float cv::MergeMertens::getExposureWeight()
  107. //
  108. public float getExposureWeight()
  109. {
  110. ThrowIfDisposed();
  111. return photo_MergeMertens_getExposureWeight_10(nativeObj);
  112. }
  113. //
  114. // C++: void cv::MergeMertens::setExposureWeight(float exposure_weight)
  115. //
  116. public void setExposureWeight(float exposure_weight)
  117. {
  118. ThrowIfDisposed();
  119. photo_MergeMertens_setExposureWeight_10(nativeObj, exposure_weight);
  120. }
  121. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  122. const string LIBNAME = "__Internal";
  123. #else
  124. const string LIBNAME = "opencvforunity";
  125. #endif
  126. // C++: void cv::MergeMertens::process(vector_Mat src, Mat& dst, Mat times, Mat response)
  127. [DllImport(LIBNAME)]
  128. private static extern void photo_MergeMertens_process_10(IntPtr nativeObj, IntPtr src_mat_nativeObj, IntPtr dst_nativeObj, IntPtr times_nativeObj, IntPtr response_nativeObj);
  129. // C++: void cv::MergeMertens::process(vector_Mat src, Mat& dst)
  130. [DllImport(LIBNAME)]
  131. private static extern void photo_MergeMertens_process_11(IntPtr nativeObj, IntPtr src_mat_nativeObj, IntPtr dst_nativeObj);
  132. // C++: float cv::MergeMertens::getContrastWeight()
  133. [DllImport(LIBNAME)]
  134. private static extern float photo_MergeMertens_getContrastWeight_10(IntPtr nativeObj);
  135. // C++: void cv::MergeMertens::setContrastWeight(float contrast_weiht)
  136. [DllImport(LIBNAME)]
  137. private static extern void photo_MergeMertens_setContrastWeight_10(IntPtr nativeObj, float contrast_weiht);
  138. // C++: float cv::MergeMertens::getSaturationWeight()
  139. [DllImport(LIBNAME)]
  140. private static extern float photo_MergeMertens_getSaturationWeight_10(IntPtr nativeObj);
  141. // C++: void cv::MergeMertens::setSaturationWeight(float saturation_weight)
  142. [DllImport(LIBNAME)]
  143. private static extern void photo_MergeMertens_setSaturationWeight_10(IntPtr nativeObj, float saturation_weight);
  144. // C++: float cv::MergeMertens::getExposureWeight()
  145. [DllImport(LIBNAME)]
  146. private static extern float photo_MergeMertens_getExposureWeight_10(IntPtr nativeObj);
  147. // C++: void cv::MergeMertens::setExposureWeight(float exposure_weight)
  148. [DllImport(LIBNAME)]
  149. private static extern void photo_MergeMertens_setExposureWeight_10(IntPtr nativeObj, float exposure_weight);
  150. // native support for java finalize()
  151. [DllImport(LIBNAME)]
  152. private static extern void photo_MergeMertens_delete(IntPtr nativeObj);
  153. }
  154. }