diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp index bc2c6e3546..ff005e8da2 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp @@ -70,6 +70,23 @@ public: */ virtual Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) = 0; + /** @brief Projects the image point backward. + + @param pt Projected point + @param K Camera intrinsic parameters + @param R Camera rotation matrix + @return Backward-projected point + */ +#if CV_VERSION_MAJOR == 4 + virtual Point2f warpPointBackward(const Point2f& pt, InputArray K, InputArray R) + { + CV_UNUSED(pt); CV_UNUSED(K); CV_UNUSED(R); + CV_Error(Error::StsNotImplemented, ""); + } +#else + virtual Point2f warpPointBackward(const Point2f& pt, InputArray K, InputArray R) = 0; +#endif + /** @brief Builds the projection maps according to the given camera data. @param src_size Source image size @@ -143,6 +160,8 @@ class CV_EXPORTS_TEMPLATE RotationWarperBase : public RotationWarper public: Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) CV_OVERRIDE; + Point2f warpPointBackward(const Point2f &pt, InputArray K, InputArray R) CV_OVERRIDE; + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) CV_OVERRIDE; Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, @@ -189,6 +208,9 @@ public: Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) CV_OVERRIDE; Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R, InputArray T); + Point2f warpPointBackward(const Point2f& pt, InputArray K, InputArray R) CV_OVERRIDE; + Point2f warpPointBackward(const Point2f& pt, InputArray K, InputArray R, InputArray T); + virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, CV_OUT OutputArray xmap, CV_OUT OutputArray ymap); Rect buildMaps(Size src_size, InputArray K, InputArray R, CV_OUT OutputArray xmap, CV_OUT OutputArray ymap) CV_OVERRIDE; @@ -228,6 +250,15 @@ public: */ Point2f warpPoint(const Point2f &pt, InputArray K, InputArray H) CV_OVERRIDE; + /** @brief Projects the image point backward. + + @param pt Projected point + @param K Camera intrinsic parameters + @param H Camera extrinsic parameters + @return Backward-projected point + */ + Point2f warpPointBackward(const Point2f &pt, InputArray K, InputArray H) CV_OVERRIDE; + /** @brief Builds the projection maps according to the given camera data. @param src_size Source image size diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp index f4a19d9c24..5e2375621e 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp @@ -61,6 +61,14 @@ Point2f RotationWarperBase
::warpPoint(const Point2f &pt, InputArray K, InputA
return uv;
}
+template ::warpPointBackward(const Point2f& pt, InputArray K, InputArray R)
+{
+ projector_.setCameraParams(K, R);
+ Point2f xy;
+ projector_.mapBackward(pt.x, pt.y, xy.x, xy.y);
+ return xy;
+}
template ::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray _xmap, OutputArray _ymap)
diff --git a/modules/stitching/include/opencv2/stitching/warpers.hpp b/modules/stitching/include/opencv2/stitching/warpers.hpp
index ff43386107..aa1ce5a6a7 100644
--- a/modules/stitching/include/opencv2/stitching/warpers.hpp
+++ b/modules/stitching/include/opencv2/stitching/warpers.hpp
@@ -65,6 +65,22 @@ namespace cv {
*/
CV_WRAP Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R);
+ /** @brief Projects the image point backward.
+
+ @param pt Projected point
+ @param K Camera intrinsic parameters
+ @param R Camera rotation matrix
+ @return Backward-projected point
+ */
+#if CV_VERSION_MAJOR == 4
+ CV_WRAP Point2f warpPointBackward(const Point2f& pt, InputArray K, InputArray R)
+ {
+ CV_UNUSED(pt); CV_UNUSED(K); CV_UNUSED(R);
+ CV_Error(Error::StsNotImplemented, "");
+ }
+#else
+ CV_WRAP Point2f warpPointBackward(const Point2f &pt, InputArray K, InputArray R);
+#endif
/** @brief Builds the projection maps according to the given camera data.
@param src_size Source image size
diff --git a/modules/stitching/src/warpers.cpp b/modules/stitching/src/warpers.cpp
index 4360590c94..85ac939074 100644
--- a/modules/stitching/src/warpers.cpp
+++ b/modules/stitching/src/warpers.cpp
@@ -92,6 +92,14 @@ Point2f PyRotationWarper::warpPoint(const Point2f &pt, InputArray K, InputArray
{
return rw.get()->warpPoint(pt, K, R);
}
+
+#if CV_VERSION_MAJOR != 4
+Point2f PyRotationWarper::warpPointBackward(const Point2f& pt, InputArray K, InputArray R)
+{
+ return rw.get()->warpPointBackward(pt, K, R);
+}
+#endif
+
Rect PyRotationWarper::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap)
{
return rw.get()->buildMaps(src_size, K, R, xmap, ymap);
@@ -164,6 +172,20 @@ Point2f PlaneWarper::warpPoint(const Point2f &pt, InputArray K, InputArray R)
Mat_