warpers.hpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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_STITCHING_WARPER_CREATORS_HPP
  43. #define OPENCV_STITCHING_WARPER_CREATORS_HPP
  44. #include "opencv2/stitching/detail/warpers.hpp"
  45. #include <string>
  46. namespace cv {
  47. class CV_EXPORTS_W PyRotationWarper
  48. {
  49. Ptr<detail::RotationWarper> rw;
  50. public:
  51. CV_WRAP PyRotationWarper(String type, float scale);
  52. CV_WRAP PyRotationWarper() {};
  53. ~PyRotationWarper() {}
  54. /** @brief Projects the image point.
  55. @param pt Source point
  56. @param K Camera intrinsic parameters
  57. @param R Camera rotation matrix
  58. @return Projected point
  59. */
  60. CV_WRAP Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R);
  61. /** @brief Builds the projection maps according to the given camera data.
  62. @param src_size Source image size
  63. @param K Camera intrinsic parameters
  64. @param R Camera rotation matrix
  65. @param xmap Projection map for the x axis
  66. @param ymap Projection map for the y axis
  67. @return Projected image minimum bounding box
  68. */
  69. CV_WRAP Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
  70. /** @brief Projects the image.
  71. @param src Source image
  72. @param K Camera intrinsic parameters
  73. @param R Camera rotation matrix
  74. @param interp_mode Interpolation mode
  75. @param border_mode Border extrapolation mode
  76. @param dst Projected image
  77. @return Project image top-left corner
  78. */
  79. CV_WRAP Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
  80. CV_OUT OutputArray dst);
  81. /** @brief Projects the image backward.
  82. @param src Projected image
  83. @param K Camera intrinsic parameters
  84. @param R Camera rotation matrix
  85. @param interp_mode Interpolation mode
  86. @param border_mode Border extrapolation mode
  87. @param dst_size Backward-projected image size
  88. @param dst Backward-projected image
  89. */
  90. CV_WRAP void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
  91. Size dst_size, CV_OUT OutputArray dst);
  92. /**
  93. @param src_size Source image bounding box
  94. @param K Camera intrinsic parameters
  95. @param R Camera rotation matrix
  96. @return Projected image minimum bounding box
  97. */
  98. CV_WRAP Rect warpRoi(Size src_size, InputArray K, InputArray R);
  99. CV_WRAP float getScale() const { return 1.f; }
  100. CV_WRAP void setScale(float) {}
  101. };
  102. //! @addtogroup stitching_warp
  103. //! @{
  104. /** @brief Image warper factories base class.
  105. */
  106. class CV_EXPORTS_W WarperCreator
  107. {
  108. public:
  109. CV_WRAP virtual ~WarperCreator() {}
  110. virtual Ptr<detail::RotationWarper> create(float scale) const = 0;
  111. };
  112. /** @brief Plane warper factory class.
  113. @sa detail::PlaneWarper
  114. */
  115. class CV_EXPORTS PlaneWarper : public WarperCreator
  116. {
  117. public:
  118. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::PlaneWarper>(scale); }
  119. };
  120. /** @brief Affine warper factory class.
  121. @sa detail::AffineWarper
  122. */
  123. class CV_EXPORTS AffineWarper : public WarperCreator
  124. {
  125. public:
  126. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::AffineWarper>(scale); }
  127. };
  128. /** @brief Cylindrical warper factory class.
  129. @sa detail::CylindricalWarper
  130. */
  131. class CV_EXPORTS CylindricalWarper: public WarperCreator
  132. {
  133. public:
  134. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::CylindricalWarper>(scale); }
  135. };
  136. /** @brief Spherical warper factory class */
  137. class CV_EXPORTS SphericalWarper: public WarperCreator
  138. {
  139. public:
  140. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::SphericalWarper>(scale); }
  141. };
  142. class CV_EXPORTS FisheyeWarper : public WarperCreator
  143. {
  144. public:
  145. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::FisheyeWarper>(scale); }
  146. };
  147. class CV_EXPORTS StereographicWarper: public WarperCreator
  148. {
  149. public:
  150. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::StereographicWarper>(scale); }
  151. };
  152. class CV_EXPORTS CompressedRectilinearWarper: public WarperCreator
  153. {
  154. float a, b;
  155. public:
  156. CompressedRectilinearWarper(float A = 1, float B = 1)
  157. {
  158. a = A; b = B;
  159. }
  160. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::CompressedRectilinearWarper>(scale, a, b); }
  161. };
  162. class CV_EXPORTS CompressedRectilinearPortraitWarper: public WarperCreator
  163. {
  164. float a, b;
  165. public:
  166. CompressedRectilinearPortraitWarper(float A = 1, float B = 1)
  167. {
  168. a = A; b = B;
  169. }
  170. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::CompressedRectilinearPortraitWarper>(scale, a, b); }
  171. };
  172. class CV_EXPORTS PaniniWarper: public WarperCreator
  173. {
  174. float a, b;
  175. public:
  176. PaniniWarper(float A = 1, float B = 1)
  177. {
  178. a = A; b = B;
  179. }
  180. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::PaniniWarper>(scale, a, b); }
  181. };
  182. class CV_EXPORTS PaniniPortraitWarper: public WarperCreator
  183. {
  184. float a, b;
  185. public:
  186. PaniniPortraitWarper(float A = 1, float B = 1)
  187. {
  188. a = A; b = B;
  189. }
  190. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::PaniniPortraitWarper>(scale, a, b); }
  191. };
  192. class CV_EXPORTS MercatorWarper: public WarperCreator
  193. {
  194. public:
  195. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::MercatorWarper>(scale); }
  196. };
  197. class CV_EXPORTS TransverseMercatorWarper: public WarperCreator
  198. {
  199. public:
  200. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::TransverseMercatorWarper>(scale); }
  201. };
  202. #ifdef HAVE_OPENCV_CUDAWARPING
  203. class PlaneWarperGpu: public WarperCreator
  204. {
  205. public:
  206. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::PlaneWarperGpu>(scale); }
  207. };
  208. class CylindricalWarperGpu: public WarperCreator
  209. {
  210. public:
  211. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::CylindricalWarperGpu>(scale); }
  212. };
  213. class SphericalWarperGpu: public WarperCreator
  214. {
  215. public:
  216. Ptr<detail::RotationWarper> create(float scale) const CV_OVERRIDE { return makePtr<detail::SphericalWarperGpu>(scale); }
  217. };
  218. #endif
  219. //! @} stitching_warp
  220. } // namespace cv
  221. #endif // OPENCV_STITCHING_WARPER_CREATORS_HPP