Commit 8f9ccc09 authored by Ilya Lavrenov's avatar Ilya Lavrenov

replaced Mat by Input/Output arrays

parent 118709fd
...@@ -51,7 +51,7 @@ namespace cv { ...@@ -51,7 +51,7 @@ namespace cv {
namespace detail { namespace detail {
template <class P> template <class P>
Point2f RotationWarperBase<P>::warpPoint(const Point2f &pt, const Mat &K, const Mat &R) Point2f RotationWarperBase<P>::warpPoint(const Point2f &pt, InputArray K, InputArray R)
{ {
projector_.setCameraParams(K, R); projector_.setCameraParams(K, R);
Point2f uv; Point2f uv;
...@@ -61,15 +61,17 @@ Point2f RotationWarperBase<P>::warpPoint(const Point2f &pt, const Mat &K, const ...@@ -61,15 +61,17 @@ Point2f RotationWarperBase<P>::warpPoint(const Point2f &pt, const Mat &K, const
template <class P> template <class P>
Rect RotationWarperBase<P>::buildMaps(Size src_size, const Mat &K, const Mat &R, Mat &xmap, Mat &ymap) Rect RotationWarperBase<P>::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray _xmap, OutputArray _ymap)
{ {
projector_.setCameraParams(K, R); projector_.setCameraParams(K, R);
Point dst_tl, dst_br; Point dst_tl, dst_br;
detectResultRoi(src_size, 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); _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); _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; float x, y;
for (int v = dst_tl.y; v <= dst_br.y; ++v) for (int v = dst_tl.y; v <= dst_br.y; ++v)
...@@ -87,8 +89,8 @@ Rect RotationWarperBase<P>::buildMaps(Size src_size, const Mat &K, const Mat &R, ...@@ -87,8 +89,8 @@ Rect RotationWarperBase<P>::buildMaps(Size src_size, const Mat &K, const Mat &R,
template <class P> template <class P>
Point RotationWarperBase<P>::warp(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, Point RotationWarperBase<P>::warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
Mat &dst) OutputArray dst)
{ {
Mat xmap, ymap; Mat xmap, ymap;
Rect dst_roi = buildMaps(src.size(), K, R, xmap, ymap); Rect dst_roi = buildMaps(src.size(), K, R, xmap, ymap);
...@@ -101,14 +103,16 @@ Point RotationWarperBase<P>::warp(const Mat &src, const Mat &K, const Mat &R, in ...@@ -101,14 +103,16 @@ Point RotationWarperBase<P>::warp(const Mat &src, const Mat &K, const Mat &R, in
template <class P> template <class P>
void RotationWarperBase<P>::warpBackward(const Mat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, void RotationWarperBase<P>::warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
Size dst_size, Mat &dst) Size dst_size, OutputArray dst)
{ {
projector_.setCameraParams(K, R); projector_.setCameraParams(K, R);
Point src_tl, src_br; Point src_tl, src_br;
detectResultRoi(dst_size, 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 xmap(dst_size, CV_32F);
Mat ymap(dst_size, CV_32F); Mat ymap(dst_size, CV_32F);
...@@ -130,7 +134,7 @@ void RotationWarperBase<P>::warpBackward(const Mat &src, const Mat &K, const Mat ...@@ -130,7 +134,7 @@ void RotationWarperBase<P>::warpBackward(const Mat &src, const Mat &K, const Mat
template <class P> template <class P>
Rect RotationWarperBase<P>::warpRoi(Size src_size, const Mat &K, const Mat &R) Rect RotationWarperBase<P>::warpRoi(Size src_size, InputArray K, InputArray R)
{ {
projector_.setCameraParams(K, R); projector_.setCameraParams(K, R);
......
...@@ -45,8 +45,10 @@ ...@@ -45,8 +45,10 @@
namespace cv { namespace cv {
namespace detail { 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(K.size() == Size(3, 3) && K.type() == CV_32F);
CV_Assert(R.size() == Size(3, 3) && R.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); 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) ...@@ -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); projector_.setCameraParams(K, R, T);
Point2f uv; Point2f uv;
...@@ -85,15 +87,17 @@ Point2f PlaneWarper::warpPoint(const Point2f &pt, const Mat &K, const Mat &R, co ...@@ -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); projector_.setCameraParams(K, R, T);
Point dst_tl, dst_br; Point dst_tl, dst_br;
detectResultRoi(src_size, 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); _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); _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; float x, y;
for (int v = dst_tl.y; v <= dst_br.y; ++v) 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 ...@@ -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, Point PlaneWarper::warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
Mat &dst) OutputArray dst)
{ {
Mat xmap, ymap; Mat xmap, ymap;
Rect dst_roi = buildMaps(src.size(), K, R, T, 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 ...@@ -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); projector_.setCameraParams(K, R, T);
...@@ -211,12 +215,12 @@ void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_b ...@@ -211,12 +215,12 @@ void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_b
#ifdef HAVE_OPENCV_CUDAWARPING #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); 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); projector_.setCameraParams(K, R, T);
...@@ -229,15 +233,15 @@ Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, const ...@@ -229,15 +233,15 @@ Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, const
return Rect(dst_tl, dst_br); 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, Point PlaneWarperGpu::warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
cuda::GpuMat &dst) cuda::GpuMat & dst)
{ {
return warp(src, K, R, Mat::zeros(3, 1, CV_32F), interp_mode, border_mode, 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, Point PlaneWarperGpu::warp(const cuda::GpuMat & src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
cuda::GpuMat &dst) cuda::GpuMat & dst)
{ {
Rect dst_roi = buildMaps(src.size(), K, R, T, d_xmap_, d_ymap_); 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()); 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, ...@@ -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); projector_.setCameraParams(K, R);
...@@ -260,8 +264,8 @@ Rect SphericalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, cu ...@@ -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, Point SphericalWarperGpu::warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
cuda::GpuMat &dst) cuda::GpuMat & dst)
{ {
Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_); Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_);
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); 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 ...@@ -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); projector_.setCameraParams(K, R);
...@@ -284,8 +288,8 @@ Rect CylindricalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &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, Point CylindricalWarperGpu::warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
cuda::GpuMat &dst) cuda::GpuMat & dst)
{ {
Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_); Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_);
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
......
...@@ -48,7 +48,7 @@ namespace detail { ...@@ -48,7 +48,7 @@ namespace detail {
/////////////////////////////////////////// PlaneWarperOcl //////////////////////////////////////////// /////////////////////////////////////////// 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); projector_.setCameraParams(K, R);
...@@ -60,18 +60,19 @@ Rect PlaneWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat & R, cons ...@@ -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); ocl::Kernel k("buildWarpPlaneMaps", ocl::stitching::warpers_oclsrc);
if (!k.empty()) if (!k.empty())
{ {
xmap.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);
ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32FC1); 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); 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); ur_kinv = r_kinv.getUMat(ACCESS_READ), ut = t.getUMat(ACCESS_READ);
k.args(ocl::KernelArg::WriteOnlyNoSize(uxmap), ocl::KernelArg::WriteOnly(uymap), k.args(ocl::KernelArg::WriteOnlyNoSize(uxmap), ocl::KernelArg::WriteOnly(uymap),
ocl::KernelArg::PtrReadOnly(ur_kinv), ocl::KernelArg::PtrReadOnly(ut), ocl::KernelArg::PtrReadOnly(ur_kinv), ocl::KernelArg::PtrReadOnly(ut),
dst_tl.x, dst_tl.y, projector_.scale); 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)) if (k.run(2, globalsize, NULL, true))
return Rect(dst_tl, dst_br); return Rect(dst_tl, dst_br);
} }
...@@ -80,13 +81,13 @@ Rect PlaneWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat & R, cons ...@@ -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); 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); Rect dst_roi = buildMaps(src.size(), K, R, T, uxmap, uymap);
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); 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); remap(src, udst, uxmap, uymap, interp_mode, border_mode);
return dst_roi.tl(); return dst_roi.tl();
...@@ -94,7 +95,7 @@ Point PlaneWarperOcl::warp(const Mat & src, const Mat & K, const Mat & R, const ...@@ -94,7 +95,7 @@ Point PlaneWarperOcl::warp(const Mat & src, const Mat & K, const Mat & R, const
/////////////////////////////////////////// SphericalWarperOcl //////////////////////////////////////// /////////////////////////////////////////// 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); projector_.setCameraParams(K, R);
...@@ -106,16 +107,17 @@ Rect SphericalWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat &R, M ...@@ -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); ocl::Kernel k("buildWarpSphericalMaps", ocl::stitching::warpers_oclsrc);
if (!k.empty()) if (!k.empty())
{ {
xmap.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);
ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32FC1); xmap.create(dsize, CV_32FC1);
ymap.create(dsize, CV_32FC1);
Mat r_kinv(1, 9, CV_32FC1, projector_.r_kinv); 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), k.args(ocl::KernelArg::WriteOnlyNoSize(uxmap), ocl::KernelArg::WriteOnly(uymap),
ocl::KernelArg::PtrReadOnly(ur_kinv), dst_tl.x, dst_tl.y, projector_.scale); 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)) if (k.run(2, globalsize, NULL, true))
return Rect(dst_tl, dst_br); return Rect(dst_tl, dst_br);
} }
...@@ -124,13 +126,13 @@ Rect SphericalWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat &R, M ...@@ -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); 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); Rect dst_roi = buildMaps(src.size(), K, R, uxmap, uymap);
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); 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); remap(src, udst, uxmap, uymap, interp_mode, border_mode);
return dst_roi.tl(); return dst_roi.tl();
...@@ -138,7 +140,7 @@ Point SphericalWarperOcl::warp(const Mat & src, const Mat & K, const Mat & R, in ...@@ -138,7 +140,7 @@ Point SphericalWarperOcl::warp(const Mat & src, const Mat & K, const Mat & R, in
/////////////////////////////////////////// CylindricalWarperOcl //////////////////////////////////////// /////////////////////////////////////////// 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); projector_.setCameraParams(K, R);
...@@ -150,16 +152,17 @@ Rect CylindricalWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat & 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); ocl::Kernel k("buildWarpCylindricalMaps", ocl::stitching::warpers_oclsrc);
if (!k.empty()) if (!k.empty())
{ {
xmap.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);
ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32FC1); xmap.create(dsize, CV_32FC1);
ymap.create(dsize, CV_32FC1);
Mat r_kinv(1, 9, CV_32FC1, projector_.r_kinv); 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), k.args(ocl::KernelArg::WriteOnlyNoSize(uxmap), ocl::KernelArg::WriteOnly(uymap),
ocl::KernelArg::PtrReadOnly(ur_kinv), dst_tl.x, dst_tl.y, projector_.scale); 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)) if (k.run(2, globalsize, NULL, true))
return Rect(dst_tl, dst_br); return Rect(dst_tl, dst_br);
} }
...@@ -168,13 +171,13 @@ Rect CylindricalWarperOcl::buildMaps(Size src_size, const Mat & K, const Mat & R ...@@ -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); 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); Rect dst_roi = buildMaps(src.size(), K, R, uxmap, uymap);
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type()); 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); remap(src, udst, uxmap, uymap, interp_mode, border_mode);
return dst_roi.tl(); return dst_roi.tl();
......
...@@ -92,9 +92,9 @@ OCL_TEST_F(SphericalWarperOclTest, Mat) ...@@ -92,9 +92,9 @@ OCL_TEST_F(SphericalWarperOclTest, Mat)
OCL_ON(warper->buildMaps(src.size(), K, R, uxmap, uymap)); 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, 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) ...@@ -115,9 +115,9 @@ OCL_TEST_F(CylindricalWarperOclTest, Mat)
OCL_ON(warper->buildMaps(src.size(), K, R, uxmap, uymap)); 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, 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) ...@@ -138,7 +138,7 @@ OCL_TEST_F(PlaneWarperOclTest, Mat)
OCL_ON(warper->buildMaps(src.size(), K, R, uxmap, uymap)); 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, 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-5);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment