cudawarping.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #ifndef OPENCV_CUDAWARPING_HPP
  43. #define OPENCV_CUDAWARPING_HPP
  44. #ifndef __cplusplus
  45. # error cudawarping.hpp header must be compiled as C++
  46. #endif
  47. #include "opencv2/core/cuda.hpp"
  48. #include "opencv2/imgproc.hpp"
  49. /**
  50. @addtogroup cuda
  51. @{
  52. @defgroup cudawarping Image Warping
  53. @}
  54. */
  55. namespace cv { namespace cuda {
  56. //! @addtogroup cudawarping
  57. //! @{
  58. /** @brief Applies a generic geometrical transformation to an image.
  59. @param src Source image.
  60. @param dst Destination image with the size the same as xmap and the type the same as src .
  61. @param xmap X values. Only CV_32FC1 type is supported.
  62. @param ymap Y values. Only CV_32FC1 type is supported.
  63. @param interpolation Interpolation method (see resize ). INTER_NEAREST , INTER_LINEAR and
  64. INTER_CUBIC are supported for now.
  65. @param borderMode Pixel extrapolation method (see borderInterpolate ). BORDER_REFLECT101 ,
  66. BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now.
  67. @param borderValue Value used in case of a constant border. By default, it is 0.
  68. @param stream Stream for the asynchronous version.
  69. The function transforms the source image using the specified map:
  70. \f[\texttt{dst} (x,y) = \texttt{src} (xmap(x,y), ymap(x,y))\f]
  71. Values of pixels with non-integer coordinates are computed using the bilinear interpolation.
  72. @sa remap
  73. */
  74. CV_EXPORTS_W void remap(InputArray src, OutputArray dst, InputArray xmap, InputArray ymap,
  75. int interpolation, int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(),
  76. Stream& stream = Stream::Null());
  77. /** @brief Resizes an image.
  78. @param src Source image.
  79. @param dst Destination image with the same type as src . The size is dsize (when it is non-zero)
  80. or the size is computed from src.size() , fx , and fy .
  81. @param dsize Destination image size. If it is zero, it is computed as:
  82. \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f]
  83. Either dsize or both fx and fy must be non-zero.
  84. @param fx Scale factor along the horizontal axis. If it is zero, it is computed as:
  85. \f[\texttt{(double)dsize.width/src.cols}\f]
  86. @param fy Scale factor along the vertical axis. If it is zero, it is computed as:
  87. \f[\texttt{(double)dsize.height/src.rows}\f]
  88. @param interpolation Interpolation method. INTER_NEAREST , INTER_LINEAR and INTER_CUBIC are
  89. supported for now.
  90. @param stream Stream for the asynchronous version.
  91. @sa resize
  92. */
  93. CV_EXPORTS_W void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null());
  94. /** @brief Applies an affine transformation to an image.
  95. @param src Source image. CV_8U , CV_16U , CV_32S , or CV_32F depth and 1, 3, or 4 channels are
  96. supported.
  97. @param dst Destination image with the same type as src . The size is dsize .
  98. @param M *2x3* Mat or UMat transformation matrix.
  99. @param dsize Size of the destination image.
  100. @param flags Combination of interpolation methods (see resize) and the optional flag
  101. WARP_INVERSE_MAP specifying that M is an inverse transformation ( dst=\>src ). Only
  102. INTER_NEAREST , INTER_LINEAR , and INTER_CUBIC interpolation methods are supported.
  103. @param borderMode
  104. @param borderValue
  105. @param stream Stream for the asynchronous version.
  106. @sa warpAffine
  107. */
  108. CV_EXPORTS void warpAffine(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags = INTER_LINEAR,
  109. int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null());
  110. CV_WRAP inline void warpAffine(InputArray src, OutputArray dst, UMat M, Size dsize, int flags = INTER_LINEAR,
  111. int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null()) {
  112. warpAffine(src, dst, InputArray(M), dsize, flags, borderMode, borderValue, stream);
  113. }
  114. CV_WRAP inline void warpAffine(InputArray src, OutputArray dst, Mat M, Size dsize, int flags = INTER_LINEAR,
  115. int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null()) {
  116. warpAffine(src, dst, InputArray(M), dsize, flags, borderMode, borderValue, stream);
  117. }
  118. /** @brief Builds transformation maps for affine transformation.
  119. @param M *2x3* Mat or UMat transformation matrix.
  120. @param inverse Flag specifying that M is an inverse transformation ( dst=\>src ).
  121. @param dsize Size of the destination image.
  122. @param xmap X values with CV_32FC1 type.
  123. @param ymap Y values with CV_32FC1 type.
  124. @param stream Stream for the asynchronous version.
  125. @sa cuda::warpAffine , cuda::remap
  126. */
  127. CV_EXPORTS void buildWarpAffineMaps(InputArray M, bool inverse, Size dsize, OutputArray xmap, OutputArray ymap, Stream& stream = Stream::Null());
  128. CV_WRAP inline void buildWarpAffineMaps(UMat M, bool inverse, Size dsize, CV_OUT GpuMat& xmap, CV_OUT GpuMat& ymap, Stream& stream = Stream::Null()) {
  129. buildWarpAffineMaps(InputArray(M), inverse, dsize, OutputArray(xmap), OutputArray(ymap), stream);
  130. }
  131. CV_WRAP inline void buildWarpAffineMaps(Mat M, bool inverse, Size dsize, CV_OUT GpuMat& xmap, CV_OUT GpuMat& ymap, Stream& stream = Stream::Null()) {
  132. buildWarpAffineMaps(InputArray(M), inverse, dsize, OutputArray(xmap), OutputArray(ymap), stream);
  133. }
  134. /** @brief Applies a perspective transformation to an image.
  135. @param src Source image. CV_8U , CV_16U , CV_32S , or CV_32F depth and 1, 3, or 4 channels are
  136. supported.
  137. @param dst Destination image with the same type as src . The size is dsize .
  138. @param M *3x3* Mat or UMat transformation matrix.
  139. @param dsize Size of the destination image.
  140. @param flags Combination of interpolation methods (see resize ) and the optional flag
  141. WARP_INVERSE_MAP specifying that M is the inverse transformation ( dst =\> src ). Only
  142. INTER_NEAREST , INTER_LINEAR , and INTER_CUBIC interpolation methods are supported.
  143. @param borderMode
  144. @param borderValue
  145. @param stream Stream for the asynchronous version.
  146. @sa warpPerspective
  147. */
  148. CV_EXPORTS void warpPerspective(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags = INTER_LINEAR,
  149. int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null());
  150. CV_WRAP inline void warpPerspective(InputArray src, OutputArray dst, UMat M, Size dsize, int flags = INTER_LINEAR,
  151. int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null()) {
  152. warpPerspective(src, dst, InputArray(M), dsize, flags, borderMode, borderValue, stream);
  153. }
  154. CV_WRAP inline void warpPerspective(InputArray src, OutputArray dst, Mat M, Size dsize, int flags = INTER_LINEAR,
  155. int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null()) {
  156. warpPerspective(src, dst, InputArray(M), dsize, flags, borderMode, borderValue, stream);
  157. }
  158. /** @brief Builds transformation maps for perspective transformation.
  159. @param M *3x3* Mat or UMat transformation matrix.
  160. @param inverse Flag specifying that M is an inverse transformation ( dst=\>src ).
  161. @param dsize Size of the destination image.
  162. @param xmap X values with CV_32FC1 type.
  163. @param ymap Y values with CV_32FC1 type.
  164. @param stream Stream for the asynchronous version.
  165. @sa cuda::warpPerspective , cuda::remap
  166. */
  167. CV_EXPORTS void buildWarpPerspectiveMaps(InputArray M, bool inverse, Size dsize, OutputArray xmap, OutputArray ymap, Stream& stream = Stream::Null());
  168. CV_WRAP inline void buildWarpPerspectiveMaps(UMat M, bool inverse, Size dsize, CV_OUT GpuMat& xmap, CV_OUT GpuMat& ymap, Stream& stream = Stream::Null()) {
  169. buildWarpPerspectiveMaps(InputArray(M), inverse, dsize, OutputArray(xmap), OutputArray(ymap), stream);
  170. }
  171. CV_WRAP inline void buildWarpPerspectiveMaps(Mat M, bool inverse, Size dsize, CV_OUT GpuMat& xmap, CV_OUT GpuMat& ymap, Stream& stream = Stream::Null()) {
  172. buildWarpPerspectiveMaps(InputArray(M), inverse, dsize, OutputArray(xmap), OutputArray(ymap), stream);
  173. }
  174. /** @brief Rotates an image around the origin (0,0) and then shifts it.
  175. @param src Source image. Supports 1, 3 or 4 channels images with CV_8U , CV_16U or CV_32F
  176. depth.
  177. @param dst Destination image with the same type as src . The size is dsize .
  178. @param dsize Size of the destination image.
  179. @param angle Angle of rotation in degrees.
  180. @param xShift Shift along the horizontal axis.
  181. @param yShift Shift along the vertical axis.
  182. @param interpolation Interpolation method. Only INTER_NEAREST , INTER_LINEAR , and INTER_CUBIC
  183. are supported.
  184. @param stream Stream for the asynchronous version.
  185. @sa cuda::warpAffine
  186. */
  187. CV_EXPORTS_W void rotate(InputArray src, OutputArray dst, Size dsize, double angle, double xShift = 0, double yShift = 0,
  188. int interpolation = INTER_LINEAR, Stream& stream = Stream::Null());
  189. /** @brief Smoothes an image and downsamples it.
  190. @param src Source image.
  191. @param dst Destination image. Will have Size((src.cols+1)/2, (src.rows+1)/2) size and the same
  192. type as src .
  193. @param stream Stream for the asynchronous version.
  194. @sa pyrDown
  195. */
  196. CV_EXPORTS_W void pyrDown(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
  197. /** @brief Upsamples an image and then smoothes it.
  198. @param src Source image.
  199. @param dst Destination image. Will have Size(src.cols\*2, src.rows\*2) size and the same type as
  200. src .
  201. @param stream Stream for the asynchronous version.
  202. */
  203. CV_EXPORTS_W void pyrUp(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
  204. //! @}
  205. }} // namespace cv { namespace cuda {
  206. #endif /* OPENCV_CUDAWARPING_HPP */