warpers.hpp 9.1 KB

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