From 7ca53cfcd49ab47b0a4317b18b4ad5fe054e01c9 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Thu, 22 Sep 2011 13:58:07 +0000 Subject: [PATCH] Added debug function to project back from pano to original image --- .../opencv2/stitching/detail/warpers.hpp | 4 +++ .../opencv2/stitching/detail/warpers_inl.hpp | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) 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 +void WarperBase

::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(x), static_cast(y), u, v); + xmap.at(y, x) = u - src_tl.x; + ymap.at(y, x) = v - src_tl.y; + } + } + + dst.create(dstSize, src.type()); + remap(src, dst, xmap, ymap, interp_mode, border_mode); +} + template Point WarperBase

::warp(const Mat &/*src*/, const Mat &/*K*/, const Mat &/*R*/, const Mat &/*T*/, Mat &/*dst*/,