warpers.hpp 22 KB

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