From 8f9ccc099bda7c2407c9373f99851a45c513e282 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 9 Jan 2014 15:21:07 +0400 Subject: [PATCH] replaced Mat by Input/Output arrays --- .../opencv2/stitching/detail/warpers.hpp | 108 +++++++++--------- .../opencv2/stitching/detail/warpers_inl.hpp | 24 ++-- modules/stitching/src/warpers.cpp | 44 +++---- modules/stitching/src/warpers_ocl.cpp | 51 +++++---- modules/stitching/test/ocl/test_warpers.cpp | 10 +- 5 files changed, 124 insertions(+), 113 deletions(-) diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp index ad4a6455b3..093f07cc1a 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp @@ -56,17 +56,17 @@ class CV_EXPORTS RotationWarper public: virtual ~RotationWarper() {} - virtual Point2f warpPoint(const Point2f &pt, const Mat &K, const Mat &R) = 0; + virtual Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) = 0; - virtual Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap) = 0; + virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) = 0; - virtual Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - Mat &dst) = 0; + virtual Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) = 0; - virtual void warpBackward(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - Size dst_size, Mat &dst) = 0; + virtual void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + Size dst_size, OutputArray dst) = 0; - virtual Rect warpRoi(Size src_size, const Mat &K, const Mat &R) = 0; + virtual Rect warpRoi(Size src_size, InputArray K, InputArray R) = 0; virtual float getScale() const { return 1.f; } virtual void setScale(float) {} @@ -75,9 +75,9 @@ public: struct CV_EXPORTS ProjectorBase { - void setCameraParams(const Mat &K = Mat::eye(3, 3, CV_32F), - const Mat &R = Mat::eye(3, 3, CV_32F), - const Mat &T = Mat::zeros(3, 1, CV_32F)); + void setCameraParams(InputArray K = Mat::eye(3, 3, CV_32F), + InputArray R = Mat::eye(3, 3, CV_32F), + InputArray T = Mat::zeros(3, 1, CV_32F)); float scale; float k[9]; @@ -92,17 +92,17 @@ template class CV_EXPORTS RotationWarperBase : public RotationWarper { public: - Point2f warpPoint(const Point2f &pt, const Mat &K, const Mat &R); + Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R); - Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap); + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap); - Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - Mat &dst); + Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst); - void warpBackward(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - Size dst_size, Mat &dst); + void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + Size dst_size, OutputArray dst); - Rect warpRoi(Size src_size, const Mat &K, const Mat &R); + Rect warpRoi(Size src_size, InputArray K, InputArray R); float getScale() const { return projector_.scale; } void setScale(float val) { projector_.scale = val; } @@ -132,14 +132,14 @@ class CV_EXPORTS PlaneWarper : public RotationWarperBase public: PlaneWarper(float scale = 1.f) { projector_.scale = scale; } - Point2f warpPoint(const Point2f &pt, const Mat &K, const Mat &R, const Mat &T); + Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R, InputArray T); - virtual Rect buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, Mat &xmap, Mat &ymap); + virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap); - virtual Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode, - Mat &dst); + virtual Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode, + OutputArray dst); - Rect warpRoi(Size src_size, const Mat &K, const Mat &R, const Mat &T); + Rect warpRoi(Size src_size, InputArray K, InputArray R, InputArray T); protected: void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br); @@ -333,7 +333,7 @@ class CV_EXPORTS PlaneWarperGpu : public PlaneWarper public: PlaneWarperGpu(float scale = 1.f) : PlaneWarper(scale) {} - Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap) + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) { Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_); d_xmap_.download(xmap); @@ -341,7 +341,7 @@ public: return result; } - Rect buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, Mat &xmap, Mat &ymap) + Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap) { Rect result = buildMaps(src_size, K, R, T, d_xmap_, d_ymap_); d_xmap_.download(xmap); @@ -349,8 +349,8 @@ public: return result; } - Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - Mat &dst) + Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) { d_src_.upload(src); Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_); @@ -358,8 +358,8 @@ public: return result; } - Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode, - Mat &dst) + Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode, + OutputArray dst) { d_src_.upload(src); Point result = warp(d_src_, K, R, T, interp_mode, border_mode, d_dst_); @@ -367,15 +367,15 @@ public: return result; } - Rect buildMaps(Size src_size, const Mat &K, const Mat &R, cuda::GpuMat &xmap, cuda::GpuMat &ymap); + Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap); - Rect buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, cuda::GpuMat &xmap, cuda::GpuMat &ymap); + Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, cuda::GpuMat & xmap, cuda::GpuMat & ymap); - Point warp(const cuda::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - cuda::GpuMat &dst); + Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode, + cuda::GpuMat & dst); - Point warp(const cuda::GpuMat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode, - cuda::GpuMat &dst); + Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode, + cuda::GpuMat & dst); private: cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_; @@ -387,7 +387,7 @@ class CV_EXPORTS SphericalWarperGpu : public SphericalWarper public: SphericalWarperGpu(float scale) : SphericalWarper(scale) {} - Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap) + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) { Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_); d_xmap_.download(xmap); @@ -395,8 +395,8 @@ public: return result; } - Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - Mat &dst) + Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) { d_src_.upload(src); Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_); @@ -404,10 +404,10 @@ public: return result; } - Rect buildMaps(Size src_size, const Mat &K, const Mat &R, cuda::GpuMat &xmap, cuda::GpuMat &ymap); + Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap); - Point warp(const cuda::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - cuda::GpuMat &dst); + Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode, + cuda::GpuMat & dst); private: cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_; @@ -419,7 +419,7 @@ class CV_EXPORTS CylindricalWarperGpu : public CylindricalWarper public: CylindricalWarperGpu(float scale) : CylindricalWarper(scale) {} - Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap) + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) { Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_); d_xmap_.download(xmap); @@ -427,8 +427,8 @@ public: return result; } - Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - Mat &dst) + Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) { d_src_.upload(src); Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_); @@ -436,10 +436,10 @@ public: return result; } - Rect buildMaps(Size src_size, const Mat &K, const Mat &R, cuda::GpuMat &xmap, cuda::GpuMat &ymap); + Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap); - Point warp(const cuda::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - cuda::GpuMat &dst); + Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode, + cuda::GpuMat & dst); private: cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_; @@ -510,18 +510,18 @@ class CV_EXPORTS PlaneWarperOcl : public PlaneWarper public: PlaneWarperOcl(float scale = 1.f) : PlaneWarper(scale) { } - virtual Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap) + virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) { return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32FC1), xmap, ymap); } - virtual Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, Mat &dst) + virtual Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst) { return warp(src, K, R, Mat::zeros(3, 1, CV_32FC1), interp_mode, border_mode, dst); } - virtual Rect buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, Mat &xmap, Mat &ymap); - virtual Point warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode, Mat &dst); + virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap); + virtual Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode, OutputArray dst); }; class CV_EXPORTS SphericalWarperOcl : public SphericalWarper @@ -529,8 +529,8 @@ class CV_EXPORTS SphericalWarperOcl : public SphericalWarper public: SphericalWarperOcl(float scale) : SphericalWarper(scale) { } - virtual Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap); - virtual Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, Mat &dst); + virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap); + virtual Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst); }; class CV_EXPORTS CylindricalWarperOcl : public CylindricalWarper @@ -538,8 +538,8 @@ class CV_EXPORTS CylindricalWarperOcl : public CylindricalWarper public: CylindricalWarperOcl(float scale) : CylindricalWarper(scale) { } - virtual Rect buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap); - virtual Point warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, Mat &dst); + virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap); + virtual Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst); }; } // namespace detail diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp index 144e9e32d4..f6eae4fa78 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp @@ -51,7 +51,7 @@ namespace cv { namespace detail { template -Point2f RotationWarperBase

::warpPoint(const Point2f &pt, const Mat &K, const Mat &R) +Point2f RotationWarperBase

::warpPoint(const Point2f &pt, InputArray K, InputArray R) { projector_.setCameraParams(K, R); Point2f uv; @@ -61,15 +61,17 @@ Point2f RotationWarperBase

::warpPoint(const Point2f &pt, const Mat &K, const template -Rect RotationWarperBase

::buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap) +Rect RotationWarperBase

::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray _xmap, OutputArray _ymap) { projector_.setCameraParams(K, R); Point dst_tl, dst_br; detectResultRoi(src_size, dst_tl, dst_br); - xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F); - ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F); + _xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F); + _ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F); + + Mat xmap = _xmap.getMat(), ymap = _ymap.getMat(); float x, y; for (int v = dst_tl.y; v <= dst_br.y; ++v) @@ -87,8 +89,8 @@ Rect RotationWarperBase

::buildMaps(Size src_size, const Mat &K, const Mat &R, template -Point RotationWarperBase

::warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - Mat &dst) +Point RotationWarperBase

::warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + OutputArray dst) { Mat xmap, ymap; Rect dst_roi = buildMaps(src.size(), K, R, xmap, ymap); @@ -101,14 +103,16 @@ Point RotationWarperBase

::warp(const Mat &src, const Mat &K, const Mat &R, in template -void RotationWarperBase

::warpBackward(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - Size dst_size, Mat &dst) +void RotationWarperBase

::warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, + Size dst_size, OutputArray dst) { projector_.setCameraParams(K, R); Point src_tl, src_br; detectResultRoi(dst_size, src_tl, src_br); - CV_Assert(src_br.x - src_tl.x + 1 == src.cols && src_br.y - src_tl.y + 1 == src.rows); + + Size size = src.size(); + CV_Assert(src_br.x - src_tl.x + 1 == size.width && src_br.y - src_tl.y + 1 == size.height); Mat xmap(dst_size, CV_32F); Mat ymap(dst_size, CV_32F); @@ -130,7 +134,7 @@ void RotationWarperBase

::warpBackward(const Mat &src, const Mat &K, const Mat template -Rect RotationWarperBase

::warpRoi(Size src_size, const Mat &K, const Mat &R) +Rect RotationWarperBase

::warpRoi(Size src_size, InputArray K, InputArray R) { projector_.setCameraParams(K, R); diff --git a/modules/stitching/src/warpers.cpp b/modules/stitching/src/warpers.cpp index 3f71f20405..eb15d44c04 100644 --- a/modules/stitching/src/warpers.cpp +++ b/modules/stitching/src/warpers.cpp @@ -45,8 +45,10 @@ namespace cv { namespace detail { -void ProjectorBase::setCameraParams(const Mat &K, const Mat &R, const Mat &T) +void ProjectorBase::setCameraParams(InputArray _K, InputArray _R, InputArray _T) { + Mat K = _K.getMat(), R = _R.getMat(), T = _T.getMat(); + CV_Assert(K.size() == Size(3, 3) && K.type() == CV_32F); CV_Assert(R.size() == Size(3, 3) && R.type() == CV_32F); CV_Assert((T.size() == Size(1, 3) || T.size() == Size(3, 1)) && T.type() == CV_32F); @@ -76,7 +78,7 @@ void ProjectorBase::setCameraParams(const Mat &K, const Mat &R, const Mat &T) } -Point2f PlaneWarper::warpPoint(const Point2f &pt, const Mat &K, const Mat &R, const Mat &T) +Point2f PlaneWarper::warpPoint(const Point2f &pt, InputArray K, InputArray R, InputArray T) { projector_.setCameraParams(K, R, T); Point2f uv; @@ -85,15 +87,17 @@ Point2f PlaneWarper::warpPoint(const Point2f &pt, const Mat &K, const Mat &R, co } -Rect PlaneWarper::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, Mat &xmap, Mat &ymap) +Rect PlaneWarper::buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray _xmap, OutputArray _ymap) { projector_.setCameraParams(K, R, T); Point dst_tl, dst_br; detectResultRoi(src_size, dst_tl, dst_br); - xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F); - ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F); + _xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F); + _ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F); + + Mat xmap = _xmap.getMat(), ymap = _ymap.getMat(); float x, y; for (int v = dst_tl.y; v <= dst_br.y; ++v) @@ -110,8 +114,8 @@ Rect PlaneWarper::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat } -Point PlaneWarper::warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode, - Mat &dst) +Point PlaneWarper::warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode, + OutputArray dst) { Mat xmap, ymap; Rect dst_roi = buildMaps(src.size(), K, R, T, xmap, ymap); @@ -123,7 +127,7 @@ Point PlaneWarper::warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T } -Rect PlaneWarper::warpRoi(Size src_size, const Mat &K, const Mat &R, const Mat &T) +Rect PlaneWarper::warpRoi(Size src_size, InputArray K, InputArray R, InputArray T) { projector_.setCameraParams(K, R, T); @@ -211,12 +215,12 @@ void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_b #ifdef HAVE_OPENCV_CUDAWARPING -Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, cuda::GpuMat &xmap, cuda::GpuMat &ymap) +Rect PlaneWarperGpu::buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap) { return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32F), xmap, ymap); } -Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, cuda::GpuMat &xmap, cuda::GpuMat &ymap) +Rect PlaneWarperGpu::buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, cuda::GpuMat & xmap, cuda::GpuMat & ymap) { projector_.setCameraParams(K, R, T); @@ -229,15 +233,15 @@ Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, const return Rect(dst_tl, dst_br); } -Point PlaneWarperGpu::warp(const cuda::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - cuda::GpuMat &dst) +Point PlaneWarperGpu::warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode, + cuda::GpuMat & dst) { return warp(src, K, R, Mat::zeros(3, 1, CV_32F), interp_mode, border_mode, dst); } -Point PlaneWarperGpu::warp(const cuda::GpuMat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode, - cuda::GpuMat &dst) +Point PlaneWarperGpu::warp(const cuda::GpuMat & src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode, + cuda::GpuMat & dst) { Rect dst_roi = buildMaps(src.size(), K, R, T, d_xmap_, d_ymap_); dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); @@ -246,7 +250,7 @@ Point PlaneWarperGpu::warp(const cuda::GpuMat &src, const Mat &K, const Mat &R, } -Rect SphericalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, cuda::GpuMat &xmap, cuda::GpuMat &ymap) +Rect SphericalWarperGpu::buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap) { projector_.setCameraParams(K, R); @@ -260,8 +264,8 @@ Rect SphericalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, cu } -Point SphericalWarperGpu::warp(const cuda::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - cuda::GpuMat &dst) +Point SphericalWarperGpu::warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode, + cuda::GpuMat & dst) { Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_); dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); @@ -270,7 +274,7 @@ Point SphericalWarperGpu::warp(const cuda::GpuMat &src, const Mat &K, const Mat } -Rect CylindricalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, cuda::GpuMat &xmap, cuda::GpuMat &ymap) +Rect CylindricalWarperGpu::buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap) { projector_.setCameraParams(K, R); @@ -284,8 +288,8 @@ Rect CylindricalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, } -Point CylindricalWarperGpu::warp(const cuda::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, - cuda::GpuMat &dst) +Point CylindricalWarperGpu::warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode, + cuda::GpuMat & dst) { Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_); dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); diff --git a/modules/stitching/src/warpers_ocl.cpp b/modules/stitching/src/warpers_ocl.cpp index 7735cbb4d6..ce4b8946d8 100644 --- a/modules/stitching/src/warpers_ocl.cpp +++ b/modules/stitching/src/warpers_ocl.cpp @@ -48,7 +48,7 @@ namespace detail { /////////////////////////////////////////// PlaneWarperOcl //////////////////////////////////////////// -Rect PlaneWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat & R, const Mat & T, Mat & xmap, Mat & ymap) +Rect PlaneWarperOcl::buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap) { projector_.setCameraParams(K, R); @@ -60,18 +60,19 @@ Rect PlaneWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat & R, cons ocl::Kernel k("buildWarpPlaneMaps", ocl::stitching::warpers_oclsrc); if (!k.empty()) { - xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32FC1); - ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32FC1); + Size dsize(dst_br.x - dst_tl.x + 1, dst_br.y - dst_tl.y + 1); + xmap.create(dsize, CV_32FC1); + ymap.create(dsize, CV_32FC1); Mat r_kinv(1, 9, CV_32FC1, projector_.r_kinv), t(1, 3, CV_32FC1, projector_.t); - UMat uxmap = xmap.getUMat(ACCESS_WRITE), uymap = ymap.getUMat(ACCESS_WRITE), + UMat uxmap = xmap.getUMat(), uymap = ymap.getUMat(), ur_kinv = r_kinv.getUMat(ACCESS_READ), ut = t.getUMat(ACCESS_READ); k.args(ocl::KernelArg::WriteOnlyNoSize(uxmap), ocl::KernelArg::WriteOnly(uymap), ocl::KernelArg::PtrReadOnly(ur_kinv), ocl::KernelArg::PtrReadOnly(ut), dst_tl.x, dst_tl.y, projector_.scale); - size_t globalsize[2] = { xmap.cols, xmap.rows }; + size_t globalsize[2] = { dsize.width, dsize.height }; if (k.run(2, globalsize, NULL, true)) return Rect(dst_tl, dst_br); } @@ -80,13 +81,13 @@ Rect PlaneWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat & R, cons return PlaneWarper::buildMaps(src_size, K, R, T, xmap, ymap); } -Point PlaneWarperOcl::warp(const Mat & src, const Mat & K, const Mat & R, const Mat & T, int interp_mode, int border_mode, Mat & dst) +Point PlaneWarperOcl::warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode, OutputArray dst) { - Mat uxmap, uymap; + UMat uxmap, uymap; Rect dst_roi = buildMaps(src.size(), K, R, T, uxmap, uymap); dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); - UMat udst = dst.getUMat(ACCESS_WRITE); + UMat udst = dst.getUMat(); remap(src, udst, uxmap, uymap, interp_mode, border_mode); return dst_roi.tl(); @@ -94,7 +95,7 @@ Point PlaneWarperOcl::warp(const Mat & src, const Mat & K, const Mat & R, const /////////////////////////////////////////// SphericalWarperOcl //////////////////////////////////////// -Rect SphericalWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat &R, Mat & xmap, Mat & ymap) +Rect SphericalWarperOcl::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) { projector_.setCameraParams(K, R); @@ -106,16 +107,17 @@ Rect SphericalWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat &R, M ocl::Kernel k("buildWarpSphericalMaps", ocl::stitching::warpers_oclsrc); if (!k.empty()) { - xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32FC1); - ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32FC1); + Size dsize(dst_br.x - dst_tl.x + 1, dst_br.y - dst_tl.y + 1); + xmap.create(dsize, CV_32FC1); + ymap.create(dsize, CV_32FC1); Mat r_kinv(1, 9, CV_32FC1, projector_.r_kinv); - UMat uxmap = xmap.getUMat(ACCESS_WRITE), uymap = ymap.getUMat(ACCESS_WRITE), ur_kinv = r_kinv.getUMat(ACCESS_READ); + UMat uxmap = xmap.getUMat(), uymap = ymap.getUMat(), ur_kinv = r_kinv.getUMat(ACCESS_READ); k.args(ocl::KernelArg::WriteOnlyNoSize(uxmap), ocl::KernelArg::WriteOnly(uymap), ocl::KernelArg::PtrReadOnly(ur_kinv), dst_tl.x, dst_tl.y, projector_.scale); - size_t globalsize[2] = { xmap.cols, xmap.rows }; + size_t globalsize[2] = { dsize.width, dsize.height }; if (k.run(2, globalsize, NULL, true)) return Rect(dst_tl, dst_br); } @@ -124,13 +126,13 @@ Rect SphericalWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat &R, M return SphericalWarper::buildMaps(src_size, K, R, xmap, ymap); } -Point SphericalWarperOcl::warp(const Mat & src, const Mat & K, const Mat & R, int interp_mode, int border_mode, Mat & dst) +Point SphericalWarperOcl::warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst) { - Mat uxmap, uymap; + UMat uxmap, uymap; Rect dst_roi = buildMaps(src.size(), K, R, uxmap, uymap); dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); - UMat udst = dst.getUMat(ACCESS_WRITE); + UMat udst = dst.getUMat(); remap(src, udst, uxmap, uymap, interp_mode, border_mode); return dst_roi.tl(); @@ -138,7 +140,7 @@ Point SphericalWarperOcl::warp(const Mat & src, const Mat & K, const Mat & R, in /////////////////////////////////////////// CylindricalWarperOcl //////////////////////////////////////// -Rect CylindricalWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat & R, Mat & xmap, Mat & ymap) +Rect CylindricalWarperOcl::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) { projector_.setCameraParams(K, R); @@ -150,16 +152,17 @@ Rect CylindricalWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat & R ocl::Kernel k("buildWarpCylindricalMaps", ocl::stitching::warpers_oclsrc); if (!k.empty()) { - xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32FC1); - ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32FC1); + Size dsize(dst_br.x - dst_tl.x + 1, dst_br.y - dst_tl.y + 1); + xmap.create(dsize, CV_32FC1); + ymap.create(dsize, CV_32FC1); Mat r_kinv(1, 9, CV_32FC1, projector_.r_kinv); - UMat uxmap = xmap.getUMat(ACCESS_WRITE), uymap = ymap.getUMat(ACCESS_WRITE), ur_kinv = r_kinv.getUMat(ACCESS_READ); + UMat uxmap = xmap.getUMat(), uymap = ymap.getUMat(), ur_kinv = r_kinv.getUMat(ACCESS_READ); k.args(ocl::KernelArg::WriteOnlyNoSize(uxmap), ocl::KernelArg::WriteOnly(uymap), ocl::KernelArg::PtrReadOnly(ur_kinv), dst_tl.x, dst_tl.y, projector_.scale); - size_t globalsize[2] = { xmap.cols, xmap.rows }; + size_t globalsize[2] = { dsize.width, dsize.height }; if (k.run(2, globalsize, NULL, true)) return Rect(dst_tl, dst_br); } @@ -168,13 +171,13 @@ Rect CylindricalWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat & R return CylindricalWarper::buildMaps(src_size, K, R, xmap, ymap); } -Point CylindricalWarperOcl::warp(const Mat & src, const Mat & K, const Mat & R, int interp_mode, int border_mode, Mat & dst) +Point CylindricalWarperOcl::warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst) { - Mat uxmap, uymap; + UMat uxmap, uymap; Rect dst_roi = buildMaps(src.size(), K, R, uxmap, uymap); dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); - UMat udst = dst.getUMat(ACCESS_WRITE); + UMat udst = dst.getUMat(); remap(src, udst, uxmap, uymap, interp_mode, border_mode); return dst_roi.tl(); diff --git a/modules/stitching/test/ocl/test_warpers.cpp b/modules/stitching/test/ocl/test_warpers.cpp index 83f0834980..d2f5dc0091 100644 --- a/modules/stitching/test/ocl/test_warpers.cpp +++ b/modules/stitching/test/ocl/test_warpers.cpp @@ -92,9 +92,9 @@ OCL_TEST_F(SphericalWarperOclTest, Mat) OCL_ON(warper->buildMaps(src.size(), K, R, uxmap, uymap)); OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst)); - OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, udst)); + OCL_ON(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, udst)); - Near(1e-5); + Near(1e-4); } } @@ -115,9 +115,9 @@ OCL_TEST_F(CylindricalWarperOclTest, Mat) OCL_ON(warper->buildMaps(src.size(), K, R, uxmap, uymap)); OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst)); - OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, udst)); + OCL_ON(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, udst)); - Near(1e-5); + Near(1e-4); } } @@ -138,7 +138,7 @@ OCL_TEST_F(PlaneWarperOclTest, Mat) OCL_ON(warper->buildMaps(src.size(), K, R, uxmap, uymap)); OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst)); - OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, udst)); + OCL_ON(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, udst)); Near(1e-5); }