diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp index 9841d99772..97e6a0a402 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp @@ -58,6 +58,8 @@ public: virtual ~Warper() {} virtual Point warp(const Mat &src, const Mat &K, const Mat &R, Mat &dst, int interp_mode, int border_mode) = 0; + virtual void warpBackward(const Mat &src, const Mat &K, const Mat &R, Mat &dst, Size dstSize, + int interp_mode, int border_mode) = 0; virtual Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, Mat &dst, int interp_mode, int border_mode) = 0; virtual Rect warpRoi(const Size &sz, const Mat &K, const Mat &R) = 0; @@ -86,6 +88,8 @@ class CV_EXPORTS WarperBase : public Warper public: Point warp(const Mat &src, const Mat &K, const Mat &R, Mat &dst, int interp_mode, int border_mode); + void warpBackward(const Mat &src, const Mat &K, const Mat &R, Mat &dst, Size dstSize, + int interp_mode, int border_mode); Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, Mat &dst, int interp_mode, int border_mode); Rect warpRoi(const Size &sz, const Mat &K, const Mat &R); diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp index b0a9e2417a..3d44269cb5 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp @@ -79,6 +79,35 @@ Point WarperBase
::warp(const Mat &src, const Mat &K, const Mat &R, Mat &dst,
return dst_tl;
}
+template ::warpBackward(const Mat &src, const Mat &K, const Mat &R, Mat &dst, Size dstSize,
+ int interp_mode, int border_mode)
+{
+ src_size_ = dstSize;
+ projector_.setCameraParams(K, R);
+
+ Point src_tl, src_br;
+ detectResultRoi(src_tl, src_br);
+ CV_Assert(src_br.x - src_tl.x + 1 == src.cols && src_br.y - src_tl.y + 1 == src.rows);
+
+ Mat xmap(dstSize, CV_32F);
+ Mat ymap(dstSize, CV_32F);
+
+ float u, v;
+ for (int y = 0; y < dstSize.height; ++y)
+ {
+ for (int x = 0; x < dstSize.width; ++x)
+ {
+ projector_.mapForward(static_cast ::warp(const Mat &/*src*/, const Mat &/*K*/, const Mat &/*R*/, const Mat &/*T*/, Mat &/*dst*/,