warpers.hpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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_WARPERS_HPP
  43. #define OPENCV_STITCHING_WARPERS_HPP
  44. #include "opencv2/core.hpp"
  45. #include "opencv2/core/cuda.hpp"
  46. #include "opencv2/imgproc.hpp"
  47. #include "opencv2/opencv_modules.hpp"
  48. namespace cv {
  49. namespace detail {
  50. //! @addtogroup stitching_warp
  51. //! @{
  52. /** @brief Rotation-only model image warper interface.
  53. */
  54. class CV_EXPORTS RotationWarper
  55. {
  56. public:
  57. virtual ~RotationWarper() {}
  58. /** @brief Projects the image point.
  59. @param pt Source point
  60. @param K Camera intrinsic parameters
  61. @param R Camera rotation matrix
  62. @return Projected point
  63. */
  64. virtual Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) = 0;
  65. /** @brief Builds the projection maps according to the given camera data.
  66. @param src_size Source image size
  67. @param K Camera intrinsic parameters
  68. @param R Camera rotation matrix
  69. @param xmap Projection map for the x axis
  70. @param ymap Projection map for the y axis
  71. @return Projected image minimum bounding box
  72. */
  73. virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) = 0;
  74. /** @brief Projects the image.
  75. @param src Source image
  76. @param K Camera intrinsic parameters
  77. @param R Camera rotation matrix
  78. @param interp_mode Interpolation mode
  79. @param border_mode Border extrapolation mode
  80. @param dst Projected image
  81. @return Project image top-left corner
  82. */
  83. virtual Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
  84. OutputArray dst) = 0;
  85. /** @brief Projects the image backward.
  86. @param src Projected 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_size Backward-projected image size
  92. @param dst Backward-projected image
  93. */
  94. virtual void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
  95. Size dst_size, OutputArray dst) = 0;
  96. /**
  97. @param src_size Source image bounding box
  98. @param K Camera intrinsic parameters
  99. @param R Camera rotation matrix
  100. @return Projected image minimum bounding box
  101. */
  102. virtual Rect warpRoi(Size src_size, InputArray K, InputArray R) = 0;
  103. virtual float getScale() const { return 1.f; }
  104. virtual void setScale(float) {}
  105. };
  106. /** @brief Base class for warping logic implementation.
  107. */
  108. struct CV_EXPORTS ProjectorBase
  109. {
  110. void setCameraParams(InputArray K = Mat::eye(3, 3, CV_32F),
  111. InputArray R = Mat::eye(3, 3, CV_32F),
  112. InputArray T = Mat::zeros(3, 1, CV_32F));
  113. float scale;
  114. float k[9];
  115. float rinv[9];
  116. float r_kinv[9];
  117. float k_rinv[9];
  118. float t[3];
  119. };
  120. /** @brief Base class for rotation-based warper using a detail::ProjectorBase_ derived class.
  121. */
  122. template <class P>
  123. class CV_EXPORTS_TEMPLATE RotationWarperBase : public RotationWarper
  124. {
  125. public:
  126. Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) CV_OVERRIDE;
  127. Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE;
  128. Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
  129. OutputArray dst) CV_OVERRIDE;
  130. void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
  131. Size dst_size, OutputArray dst) CV_OVERRIDE;
  132. Rect warpRoi(Size src_size, InputArray K, InputArray R) CV_OVERRIDE;
  133. float getScale() const CV_OVERRIDE{ return projector_.scale; }
  134. void setScale(float val) CV_OVERRIDE { projector_.scale = val; }
  135. protected:
  136. // Detects ROI of the destination image. It's correct for any projection.
  137. virtual void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br);
  138. // Detects ROI of the destination image by walking over image border.
  139. // Correctness for any projection isn't guaranteed.
  140. void detectResultRoiByBorder(Size src_size, Point &dst_tl, Point &dst_br);
  141. P projector_;
  142. };
  143. struct CV_EXPORTS PlaneProjector : ProjectorBase
  144. {
  145. void mapForward(float x, float y, float &u, float &v);
  146. void mapBackward(float u, float v, float &x, float &y);
  147. };
  148. /** @brief Warper that maps an image onto the z = 1 plane.
  149. */
  150. class CV_EXPORTS PlaneWarper : public RotationWarperBase<PlaneProjector>
  151. {
  152. public:
  153. /** @brief Construct an instance of the plane warper class.
  154. @param scale Projected image scale multiplier
  155. */
  156. PlaneWarper(float scale = 1.f) { projector_.scale = scale; }
  157. Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) CV_OVERRIDE;
  158. Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R, InputArray T);
  159. virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap);
  160. Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE;
  161. Point warp(InputArray src, InputArray K, InputArray R,
  162. int interp_mode, int border_mode, OutputArray dst) CV_OVERRIDE;
  163. virtual Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
  164. OutputArray dst);
  165. Rect warpRoi(Size src_size, InputArray K, InputArray R) CV_OVERRIDE;
  166. Rect warpRoi(Size src_size, InputArray K, InputArray R, InputArray T);
  167. protected:
  168. void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE;
  169. };
  170. /** @brief Affine warper that uses rotations and translations
  171. Uses affine transformation in homogeneous coordinates to represent both rotation and
  172. translation in camera rotation matrix.
  173. */
  174. class CV_EXPORTS AffineWarper : public PlaneWarper
  175. {
  176. public:
  177. /** @brief Construct an instance of the affine warper class.
  178. @param scale Projected image scale multiplier
  179. */
  180. AffineWarper(float scale = 1.f) : PlaneWarper(scale) {}
  181. /** @brief Projects the image point.
  182. @param pt Source point
  183. @param K Camera intrinsic parameters
  184. @param H Camera extrinsic parameters
  185. @return Projected point
  186. */
  187. Point2f warpPoint(const Point2f &pt, InputArray K, InputArray H) CV_OVERRIDE;
  188. /** @brief Builds the projection maps according to the given camera data.
  189. @param src_size Source image size
  190. @param K Camera intrinsic parameters
  191. @param H Camera extrinsic parameters
  192. @param xmap Projection map for the x axis
  193. @param ymap Projection map for the y axis
  194. @return Projected image minimum bounding box
  195. */
  196. Rect buildMaps(Size src_size, InputArray K, InputArray H, OutputArray xmap, OutputArray ymap) CV_OVERRIDE;
  197. /** @brief Projects the image.
  198. @param src Source image
  199. @param K Camera intrinsic parameters
  200. @param H Camera extrinsic parameters
  201. @param interp_mode Interpolation mode
  202. @param border_mode Border extrapolation mode
  203. @param dst Projected image
  204. @return Project image top-left corner
  205. */
  206. Point warp(InputArray src, InputArray K, InputArray H,
  207. int interp_mode, int border_mode, OutputArray dst) CV_OVERRIDE;
  208. /**
  209. @param src_size Source image bounding box
  210. @param K Camera intrinsic parameters
  211. @param H Camera extrinsic parameters
  212. @return Projected image minimum bounding box
  213. */
  214. Rect warpRoi(Size src_size, InputArray K, InputArray H) CV_OVERRIDE;
  215. protected:
  216. /** @brief Extracts rotation and translation matrices from matrix H representing
  217. affine transformation in homogeneous coordinates
  218. */
  219. void getRTfromHomogeneous(InputArray H, Mat &R, Mat &T);
  220. };
  221. struct CV_EXPORTS SphericalProjector : ProjectorBase
  222. {
  223. void mapForward(float x, float y, float &u, float &v);
  224. void mapBackward(float u, float v, float &x, float &y);
  225. };
  226. /** @brief Warper that maps an image onto the unit sphere located at the origin.
  227. Projects image onto unit sphere with origin at (0, 0, 0) and radius scale, measured in pixels.
  228. A 360 panorama would therefore have a resulting width of 2 * scale * PI pixels.
  229. Poles are located at (0, -1, 0) and (0, 1, 0) points.
  230. */
  231. class CV_EXPORTS SphericalWarper : public RotationWarperBase<SphericalProjector>
  232. {
  233. public:
  234. /** @brief Construct an instance of the spherical warper class.
  235. @param scale Radius of the projected sphere, in pixels. An image spanning the
  236. whole sphere will have a width of 2 * scale * PI pixels.
  237. */
  238. SphericalWarper(float scale) { projector_.scale = scale; }
  239. Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE;
  240. Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst) CV_OVERRIDE;
  241. protected:
  242. void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE;
  243. };
  244. struct CV_EXPORTS CylindricalProjector : ProjectorBase
  245. {
  246. void mapForward(float x, float y, float &u, float &v);
  247. void mapBackward(float u, float v, float &x, float &y);
  248. };
  249. /** @brief Warper that maps an image onto the x\*x + z\*z = 1 cylinder.
  250. */
  251. class CV_EXPORTS CylindricalWarper : public RotationWarperBase<CylindricalProjector>
  252. {
  253. public:
  254. /** @brief Construct an instance of the cylindrical warper class.
  255. @param scale Projected image scale multiplier
  256. */
  257. CylindricalWarper(float scale) { projector_.scale = scale; }
  258. Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE;
  259. Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst) CV_OVERRIDE;
  260. protected:
  261. void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE
  262. {
  263. RotationWarperBase<CylindricalProjector>::detectResultRoiByBorder(src_size, dst_tl, dst_br);
  264. }
  265. };
  266. struct CV_EXPORTS FisheyeProjector : ProjectorBase
  267. {
  268. void mapForward(float x, float y, float &u, float &v);
  269. void mapBackward(float u, float v, float &x, float &y);
  270. };
  271. class CV_EXPORTS FisheyeWarper : public RotationWarperBase<FisheyeProjector>
  272. {
  273. public:
  274. FisheyeWarper(float scale) { projector_.scale = scale; }
  275. };
  276. struct CV_EXPORTS StereographicProjector : ProjectorBase
  277. {
  278. void mapForward(float x, float y, float &u, float &v);
  279. void mapBackward(float u, float v, float &x, float &y);
  280. };
  281. class CV_EXPORTS StereographicWarper : public RotationWarperBase<StereographicProjector>
  282. {
  283. public:
  284. StereographicWarper(float scale) { projector_.scale = scale; }
  285. };
  286. struct CV_EXPORTS CompressedRectilinearProjector : ProjectorBase
  287. {
  288. float a, b;
  289. void mapForward(float x, float y, float &u, float &v);
  290. void mapBackward(float u, float v, float &x, float &y);
  291. };
  292. class CV_EXPORTS CompressedRectilinearWarper : public RotationWarperBase<CompressedRectilinearProjector>
  293. {
  294. public:
  295. CompressedRectilinearWarper(float scale, float A = 1, float B = 1)
  296. {
  297. projector_.a = A;
  298. projector_.b = B;
  299. projector_.scale = scale;
  300. }
  301. };
  302. struct CV_EXPORTS CompressedRectilinearPortraitProjector : ProjectorBase
  303. {
  304. float a, b;
  305. void mapForward(float x, float y, float &u, float &v);
  306. void mapBackward(float u, float v, float &x, float &y);
  307. };
  308. class CV_EXPORTS CompressedRectilinearPortraitWarper : public RotationWarperBase<CompressedRectilinearPortraitProjector>
  309. {
  310. public:
  311. CompressedRectilinearPortraitWarper(float scale, float A = 1, float B = 1)
  312. {
  313. projector_.a = A;
  314. projector_.b = B;
  315. projector_.scale = scale;
  316. }
  317. };
  318. struct CV_EXPORTS PaniniProjector : ProjectorBase
  319. {
  320. float a, b;
  321. void mapForward(float x, float y, float &u, float &v);
  322. void mapBackward(float u, float v, float &x, float &y);
  323. };
  324. class CV_EXPORTS PaniniWarper : public RotationWarperBase<PaniniProjector>
  325. {
  326. public:
  327. PaniniWarper(float scale, float A = 1, float B = 1)
  328. {
  329. projector_.a = A;
  330. projector_.b = B;
  331. projector_.scale = scale;
  332. }
  333. };
  334. struct CV_EXPORTS PaniniPortraitProjector : ProjectorBase
  335. {
  336. float a, b;
  337. void mapForward(float x, float y, float &u, float &v);
  338. void mapBackward(float u, float v, float &x, float &y);
  339. };
  340. class CV_EXPORTS PaniniPortraitWarper : public RotationWarperBase<PaniniPortraitProjector>
  341. {
  342. public:
  343. PaniniPortraitWarper(float scale, float A = 1, float B = 1)
  344. {
  345. projector_.a = A;
  346. projector_.b = B;
  347. projector_.scale = scale;
  348. }
  349. };
  350. struct CV_EXPORTS MercatorProjector : ProjectorBase
  351. {
  352. void mapForward(float x, float y, float &u, float &v);
  353. void mapBackward(float u, float v, float &x, float &y);
  354. };
  355. class CV_EXPORTS MercatorWarper : public RotationWarperBase<MercatorProjector>
  356. {
  357. public:
  358. MercatorWarper(float scale) { projector_.scale = scale; }
  359. };
  360. struct CV_EXPORTS TransverseMercatorProjector : ProjectorBase
  361. {
  362. void mapForward(float x, float y, float &u, float &v);
  363. void mapBackward(float u, float v, float &x, float &y);
  364. };
  365. class CV_EXPORTS TransverseMercatorWarper : public RotationWarperBase<TransverseMercatorProjector>
  366. {
  367. public:
  368. TransverseMercatorWarper(float scale) { projector_.scale = scale; }
  369. };
  370. class CV_EXPORTS PlaneWarperGpu : public PlaneWarper
  371. {
  372. public:
  373. PlaneWarperGpu(float scale = 1.f) : PlaneWarper(scale) {}
  374. // WARNING: unreachable code using Ninja
  375. #if defined _MSC_VER && _MSC_VER >= 1920
  376. #pragma warning(push)
  377. #pragma warning(disable: 4702)
  378. #endif
  379. Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE
  380. {
  381. Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_);
  382. d_xmap_.download(xmap);
  383. d_ymap_.download(ymap);
  384. return result;
  385. }
  386. Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap) CV_OVERRIDE
  387. {
  388. Rect result = buildMaps(src_size, K, R, T, d_xmap_, d_ymap_);
  389. d_xmap_.download(xmap);
  390. d_ymap_.download(ymap);
  391. return result;
  392. }
  393. Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
  394. OutputArray dst) CV_OVERRIDE
  395. {
  396. d_src_.upload(src);
  397. Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_);
  398. d_dst_.download(dst);
  399. return result;
  400. }
  401. Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
  402. OutputArray dst) CV_OVERRIDE
  403. {
  404. d_src_.upload(src);
  405. Point result = warp(d_src_, K, R, T, interp_mode, border_mode, d_dst_);
  406. d_dst_.download(dst);
  407. return result;
  408. }
  409. #if defined _MSC_VER && _MSC_VER >= 1920
  410. #pragma warning(pop)
  411. #endif
  412. Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
  413. Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
  414. Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
  415. cuda::GpuMat & dst);
  416. Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
  417. cuda::GpuMat & dst);
  418. private:
  419. cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
  420. };
  421. class CV_EXPORTS SphericalWarperGpu : public SphericalWarper
  422. {
  423. public:
  424. SphericalWarperGpu(float scale) : SphericalWarper(scale) {}
  425. // WARNING: unreachable code using Ninja
  426. #if defined _MSC_VER && _MSC_VER >= 1920
  427. #pragma warning(push)
  428. #pragma warning(disable: 4702)
  429. #endif
  430. Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE
  431. {
  432. Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_);
  433. d_xmap_.download(xmap);
  434. d_ymap_.download(ymap);
  435. return result;
  436. }
  437. Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
  438. OutputArray dst) CV_OVERRIDE
  439. {
  440. d_src_.upload(src);
  441. Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_);
  442. d_dst_.download(dst);
  443. return result;
  444. }
  445. #if defined _MSC_VER && _MSC_VER >= 1920
  446. #pragma warning(pop)
  447. #endif
  448. Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
  449. Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
  450. cuda::GpuMat & dst);
  451. private:
  452. cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
  453. };
  454. class CV_EXPORTS CylindricalWarperGpu : public CylindricalWarper
  455. {
  456. public:
  457. CylindricalWarperGpu(float scale) : CylindricalWarper(scale) {}
  458. // WARNING: unreachable code using Ninja
  459. #if defined _MSC_VER && _MSC_VER >= 1920
  460. #pragma warning(push)
  461. #pragma warning(disable: 4702)
  462. #endif
  463. Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE
  464. {
  465. Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_);
  466. d_xmap_.download(xmap);
  467. d_ymap_.download(ymap);
  468. return result;
  469. }
  470. Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
  471. OutputArray dst) CV_OVERRIDE
  472. {
  473. d_src_.upload(src);
  474. Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_);
  475. d_dst_.download(dst);
  476. return result;
  477. }
  478. #if defined _MSC_VER && _MSC_VER >= 1920
  479. #pragma warning(pop)
  480. #endif
  481. Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
  482. Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
  483. cuda::GpuMat & dst);
  484. private:
  485. cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
  486. };
  487. struct CV_EXPORTS SphericalPortraitProjector : ProjectorBase
  488. {
  489. void mapForward(float x, float y, float &u, float &v);
  490. void mapBackward(float u, float v, float &x, float &y);
  491. };
  492. // Projects image onto unit sphere with origin at (0, 0, 0).
  493. // Poles are located NOT at (0, -1, 0) and (0, 1, 0) points, BUT at (1, 0, 0) and (-1, 0, 0) points.
  494. class CV_EXPORTS SphericalPortraitWarper : public RotationWarperBase<SphericalPortraitProjector>
  495. {
  496. public:
  497. SphericalPortraitWarper(float scale) { projector_.scale = scale; }
  498. protected:
  499. void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE;
  500. };
  501. struct CV_EXPORTS CylindricalPortraitProjector : ProjectorBase
  502. {
  503. void mapForward(float x, float y, float &u, float &v);
  504. void mapBackward(float u, float v, float &x, float &y);
  505. };
  506. class CV_EXPORTS CylindricalPortraitWarper : public RotationWarperBase<CylindricalPortraitProjector>
  507. {
  508. public:
  509. CylindricalPortraitWarper(float scale) { projector_.scale = scale; }
  510. protected:
  511. void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE
  512. {
  513. RotationWarperBase<CylindricalPortraitProjector>::detectResultRoiByBorder(src_size, dst_tl, dst_br);
  514. }
  515. };
  516. struct CV_EXPORTS PlanePortraitProjector : ProjectorBase
  517. {
  518. void mapForward(float x, float y, float &u, float &v);
  519. void mapBackward(float u, float v, float &x, float &y);
  520. };
  521. class CV_EXPORTS PlanePortraitWarper : public RotationWarperBase<PlanePortraitProjector>
  522. {
  523. public:
  524. PlanePortraitWarper(float scale) { projector_.scale = scale; }
  525. protected:
  526. void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) CV_OVERRIDE
  527. {
  528. RotationWarperBase<PlanePortraitProjector>::detectResultRoiByBorder(src_size, dst_tl, dst_br);
  529. }
  530. };
  531. //! @} stitching_warp
  532. } // namespace detail
  533. } // namespace cv
  534. #include "warpers_inl.hpp"
  535. #endif // OPENCV_STITCHING_WARPERS_HPP