mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
Merge pull request #979 from jet47:gpuwarping-refactoring
This commit is contained in:
commit
52a9378257
@ -9,7 +9,7 @@ gpu::remap
|
||||
--------------
|
||||
Applies a generic geometrical transformation to an image.
|
||||
|
||||
.. ocv:function:: void gpu::remap( const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap, int interpolation, int borderMode=BORDER_CONSTANT, Scalar borderValue=Scalar(), Stream& stream=Stream::Null() )
|
||||
.. ocv:function:: void gpu::remap(InputArray src, OutputArray dst, InputArray xmap, InputArray ymap, int interpolation, int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null())
|
||||
|
||||
:param src: Source image.
|
||||
|
||||
@ -43,7 +43,7 @@ gpu::resize
|
||||
---------------
|
||||
Resizes an image.
|
||||
|
||||
.. ocv:function:: void gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null())
|
||||
.. ocv:function:: void gpu::resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null())
|
||||
|
||||
:param src: Source image.
|
||||
|
||||
@ -80,7 +80,7 @@ gpu::warpAffine
|
||||
-------------------
|
||||
Applies an affine transformation to an image.
|
||||
|
||||
.. ocv:function:: void gpu::warpAffine( const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, Scalar borderValue=Scalar(), Stream& stream=Stream::Null() )
|
||||
.. ocv:function:: void gpu::warpAffine(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags = INTER_LINEAR, int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null())
|
||||
|
||||
:param src: Source image. ``CV_8U`` , ``CV_16U`` , ``CV_32S`` , or ``CV_32F`` depth and 1, 3, or 4 channels are supported.
|
||||
|
||||
@ -102,7 +102,7 @@ gpu::buildWarpAffineMaps
|
||||
------------------------
|
||||
Builds transformation maps for affine transformation.
|
||||
|
||||
.. ocv:function:: void gpu::buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null())
|
||||
.. ocv:function:: void gpu::buildWarpAffineMaps(InputArray M, bool inverse, Size dsize, OutputArray xmap, OutputArray ymap, Stream& stream = Stream::Null())
|
||||
|
||||
:param M: *2x3* transformation matrix.
|
||||
|
||||
@ -124,7 +124,7 @@ gpu::warpPerspective
|
||||
------------------------
|
||||
Applies a perspective transformation to an image.
|
||||
|
||||
.. ocv:function:: void gpu::warpPerspective( const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, Scalar borderValue=Scalar(), Stream& stream=Stream::Null() )
|
||||
.. ocv:function:: void gpu::warpPerspective(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags = INTER_LINEAR, int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null())
|
||||
|
||||
:param src: Source image. ``CV_8U`` , ``CV_16U`` , ``CV_32S`` , or ``CV_32F`` depth and 1, 3, or 4 channels are supported.
|
||||
|
||||
@ -146,7 +146,7 @@ gpu::buildWarpPerspectiveMaps
|
||||
-----------------------------
|
||||
Builds transformation maps for perspective transformation.
|
||||
|
||||
.. ocv:function:: void gpu::buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null())
|
||||
.. ocv:function:: void gpu::buildWarpAffineMaps(InputArray M, bool inverse, Size dsize, OutputArray xmap, OutputArray ymap, Stream& stream = Stream::Null())
|
||||
|
||||
:param M: *3x3* transformation matrix.
|
||||
|
||||
@ -164,11 +164,41 @@ Builds transformation maps for perspective transformation.
|
||||
|
||||
|
||||
|
||||
gpu::buildWarpPlaneMaps
|
||||
-----------------------
|
||||
Builds plane warping maps.
|
||||
|
||||
.. ocv:function:: void gpu::buildWarpPlaneMaps(Size src_size, Rect dst_roi, InputArray K, InputArray R, InputArray T, float scale, OutputArray map_x, OutputArray map_y, Stream& stream = Stream::Null())
|
||||
|
||||
:param stream: Stream for the asynchronous version.
|
||||
|
||||
|
||||
|
||||
gpu::buildWarpCylindricalMaps
|
||||
-----------------------------
|
||||
Builds cylindrical warping maps.
|
||||
|
||||
.. ocv:function:: void gpu::buildWarpCylindricalMaps(Size src_size, Rect dst_roi, InputArray K, InputArray R, float scale, OutputArray map_x, OutputArray map_y, Stream& stream = Stream::Null())
|
||||
|
||||
:param stream: Stream for the asynchronous version.
|
||||
|
||||
|
||||
|
||||
gpu::buildWarpSphericalMaps
|
||||
---------------------------
|
||||
Builds spherical warping maps.
|
||||
|
||||
.. ocv:function:: void gpu::buildWarpSphericalMaps(Size src_size, Rect dst_roi, InputArray K, InputArray R, float scale, OutputArray map_x, OutputArray map_y, Stream& stream = Stream::Null())
|
||||
|
||||
:param stream: Stream for the asynchronous version.
|
||||
|
||||
|
||||
|
||||
gpu::rotate
|
||||
---------------
|
||||
Rotates an image around the origin (0,0) and then shifts it.
|
||||
|
||||
.. ocv:function:: void gpu::rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift = 0, double yShift = 0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null())
|
||||
.. ocv:function:: void gpu::rotate(InputArray src, OutputArray dst, Size dsize, double angle, double xShift = 0, double yShift = 0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null())
|
||||
|
||||
:param src: Source image. Supports 1, 3 or 4 channels images with ``CV_8U`` , ``CV_16U`` or ``CV_32F`` depth.
|
||||
|
||||
@ -190,41 +220,11 @@ Rotates an image around the origin (0,0) and then shifts it.
|
||||
|
||||
|
||||
|
||||
gpu::buildWarpPlaneMaps
|
||||
-----------------------
|
||||
Builds plane warping maps.
|
||||
|
||||
.. ocv:function:: void gpu::buildWarpPlaneMaps( Size src_size, Rect dst_roi, const Mat & K, const Mat& R, const Mat & T, float scale, GpuMat& map_x, GpuMat& map_y, Stream& stream=Stream::Null() )
|
||||
|
||||
:param stream: Stream for the asynchronous version.
|
||||
|
||||
|
||||
|
||||
gpu::buildWarpCylindricalMaps
|
||||
-----------------------------
|
||||
Builds cylindrical warping maps.
|
||||
|
||||
.. ocv:function:: void gpu::buildWarpCylindricalMaps( Size src_size, Rect dst_roi, const Mat & K, const Mat& R, float scale, GpuMat& map_x, GpuMat& map_y, Stream& stream=Stream::Null() )
|
||||
|
||||
:param stream: Stream for the asynchronous version.
|
||||
|
||||
|
||||
|
||||
gpu::buildWarpSphericalMaps
|
||||
---------------------------
|
||||
Builds spherical warping maps.
|
||||
|
||||
.. ocv:function:: void gpu::buildWarpSphericalMaps( Size src_size, Rect dst_roi, const Mat & K, const Mat& R, float scale, GpuMat& map_x, GpuMat& map_y, Stream& stream=Stream::Null() )
|
||||
|
||||
:param stream: Stream for the asynchronous version.
|
||||
|
||||
|
||||
|
||||
gpu::pyrDown
|
||||
-------------------
|
||||
Smoothes an image and downsamples it.
|
||||
|
||||
.. ocv:function:: void gpu::pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null())
|
||||
.. ocv:function:: void gpu::pyrDown(InputArray src, OutputArray dst, Stream& stream = Stream::Null())
|
||||
|
||||
:param src: Source image.
|
||||
|
||||
@ -240,7 +240,7 @@ gpu::pyrUp
|
||||
-------------------
|
||||
Upsamples an image and then smoothes it.
|
||||
|
||||
.. ocv:function:: void gpu::pyrUp(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null())
|
||||
.. ocv:function:: void gpu::pyrUp(InputArray src, OutputArray dst, Stream& stream = Stream::Null())
|
||||
|
||||
:param src: Source image.
|
||||
|
||||
|
@ -54,78 +54,60 @@ namespace cv { namespace gpu {
|
||||
|
||||
//! DST[x,y] = SRC[xmap[x,y],ymap[x,y]]
|
||||
//! supports only CV_32FC1 map type
|
||||
CV_EXPORTS void remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap,
|
||||
CV_EXPORTS void remap(InputArray src, OutputArray dst, InputArray xmap, InputArray ymap,
|
||||
int interpolation, int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(),
|
||||
Stream& stream = Stream::Null());
|
||||
|
||||
//! resizes the image
|
||||
//! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_AREA
|
||||
CV_EXPORTS void resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null());
|
||||
CV_EXPORTS void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null());
|
||||
|
||||
//! warps the image using affine transformation
|
||||
//! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
|
||||
CV_EXPORTS void warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR,
|
||||
CV_EXPORTS void warpAffine(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags = INTER_LINEAR,
|
||||
int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null());
|
||||
|
||||
CV_EXPORTS void buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null());
|
||||
CV_EXPORTS void buildWarpAffineMaps(InputArray M, bool inverse, Size dsize, OutputArray xmap, OutputArray ymap, Stream& stream = Stream::Null());
|
||||
|
||||
//! warps the image using perspective transformation
|
||||
//! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
|
||||
CV_EXPORTS void warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR,
|
||||
CV_EXPORTS void warpPerspective(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags = INTER_LINEAR,
|
||||
int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null());
|
||||
|
||||
CV_EXPORTS void buildWarpPerspectiveMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null());
|
||||
CV_EXPORTS void buildWarpPerspectiveMaps(InputArray M, bool inverse, Size dsize, OutputArray xmap, OutputArray ymap, Stream& stream = Stream::Null());
|
||||
|
||||
//! builds plane warping maps
|
||||
CV_EXPORTS void buildWarpPlaneMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, const Mat &T, float scale,
|
||||
GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null());
|
||||
CV_EXPORTS void buildWarpPlaneMaps(Size src_size, Rect dst_roi, InputArray K, InputArray R, InputArray T, float scale,
|
||||
OutputArray map_x, OutputArray map_y, Stream& stream = Stream::Null());
|
||||
|
||||
//! builds cylindrical warping maps
|
||||
CV_EXPORTS void buildWarpCylindricalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, float scale,
|
||||
GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null());
|
||||
CV_EXPORTS void buildWarpCylindricalMaps(Size src_size, Rect dst_roi, InputArray K, InputArray R, float scale,
|
||||
OutputArray map_x, OutputArray map_y, Stream& stream = Stream::Null());
|
||||
|
||||
//! builds spherical warping maps
|
||||
CV_EXPORTS void buildWarpSphericalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, float scale,
|
||||
GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null());
|
||||
CV_EXPORTS void buildWarpSphericalMaps(Size src_size, Rect dst_roi, InputArray K, InputArray R, float scale,
|
||||
OutputArray map_x, OutputArray map_y, Stream& stream = Stream::Null());
|
||||
|
||||
//! rotates an image around the origin (0,0) and then shifts it
|
||||
//! supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
|
||||
//! supports 1, 3 or 4 channels images with CV_8U, CV_16U or CV_32F depth
|
||||
CV_EXPORTS void rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift = 0, double yShift = 0,
|
||||
CV_EXPORTS void rotate(InputArray src, OutputArray dst, Size dsize, double angle, double xShift = 0, double yShift = 0,
|
||||
int interpolation = INTER_LINEAR, Stream& stream = Stream::Null());
|
||||
|
||||
//! smoothes the source image and downsamples it
|
||||
CV_EXPORTS void pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
|
||||
CV_EXPORTS void pyrDown(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
|
||||
|
||||
//! upsamples the source image and then smoothes it
|
||||
CV_EXPORTS void pyrUp(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
|
||||
CV_EXPORTS void pyrUp(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
|
||||
|
||||
class CV_EXPORTS ImagePyramid
|
||||
class CV_EXPORTS ImagePyramid : public Algorithm
|
||||
{
|
||||
public:
|
||||
inline ImagePyramid() : nLayers_(0) {}
|
||||
inline ImagePyramid(const GpuMat& img, int nLayers, Stream& stream = Stream::Null())
|
||||
{
|
||||
build(img, nLayers, stream);
|
||||
}
|
||||
|
||||
void build(const GpuMat& img, int nLayers, Stream& stream = Stream::Null());
|
||||
|
||||
void getLayer(GpuMat& outImg, Size outRoi, Stream& stream = Stream::Null()) const;
|
||||
|
||||
inline void release()
|
||||
{
|
||||
layer0_.release();
|
||||
pyramid_.clear();
|
||||
nLayers_ = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
GpuMat layer0_;
|
||||
std::vector<GpuMat> pyramid_;
|
||||
int nLayers_;
|
||||
virtual void getLayer(OutputArray outImg, Size outRoi, Stream& stream = Stream::Null()) const = 0;
|
||||
};
|
||||
|
||||
CV_EXPORTS Ptr<ImagePyramid> createImagePyramid(InputArray img, int nLayers = -1, Stream& stream = Stream::Null());
|
||||
|
||||
}} // namespace cv { namespace gpu {
|
||||
|
||||
#endif /* __OPENCV_GPUWARPING_HPP__ */
|
||||
|
@ -515,45 +515,6 @@ PERF_TEST_P(Sz_Depth_Cn, PyrUp,
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ImagePyramidBuild
|
||||
|
||||
PERF_TEST_P(Sz_Depth_Cn, ImagePyramidBuild,
|
||||
Combine(GPU_TYPICAL_MAT_SIZES,
|
||||
Values(CV_8U, CV_16U, CV_32F),
|
||||
GPU_CHANNELS_1_3_4))
|
||||
{
|
||||
const cv::Size size = GET_PARAM(0);
|
||||
const int depth = GET_PARAM(1);
|
||||
const int channels = GET_PARAM(2);
|
||||
|
||||
const int type = CV_MAKE_TYPE(depth, channels);
|
||||
|
||||
cv::Mat src(size, type);
|
||||
declare.in(src, WARMUP_RNG);
|
||||
|
||||
const int nLayers = 5;
|
||||
const cv::Size dstSize(size.width / 2 + 10, size.height / 2 + 10);
|
||||
|
||||
if (PERF_RUN_GPU())
|
||||
{
|
||||
const cv::gpu::GpuMat d_src(src);
|
||||
|
||||
cv::gpu::ImagePyramid d_pyr;
|
||||
|
||||
TEST_CYCLE() d_pyr.build(d_src, nLayers);
|
||||
|
||||
cv::gpu::GpuMat dst;
|
||||
d_pyr.getLayer(dst, dstSize);
|
||||
|
||||
GPU_SANITY_CHECK(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
FAIL_NO_CPU();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ImagePyramidGetLayer
|
||||
|
||||
@ -579,9 +540,9 @@ PERF_TEST_P(Sz_Depth_Cn, ImagePyramidGetLayer,
|
||||
const cv::gpu::GpuMat d_src(src);
|
||||
cv::gpu::GpuMat dst;
|
||||
|
||||
cv::gpu::ImagePyramid d_pyr(d_src, nLayers);
|
||||
cv::Ptr<cv::gpu::ImagePyramid> d_pyr = cv::gpu::createImagePyramid(d_src, nLayers);
|
||||
|
||||
TEST_CYCLE() d_pyr.getLayer(dst, dstSize);
|
||||
TEST_CYCLE() d_pyr->getLayer(dst, dstSize);
|
||||
|
||||
GPU_SANITY_CHECK(dst);
|
||||
}
|
||||
|
@ -42,14 +42,15 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
#if !defined HAVE_CUDA || defined(CUDA_DISABLER)
|
||||
|
||||
void cv::gpu::pyrDown(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::pyrDown(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::pyrUp(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::pyrUp(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::ImagePyramid::build(const GpuMat&, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::ImagePyramid::getLayer(GpuMat&, Size, Stream&) const { throw_no_cuda(); }
|
||||
Ptr<ImagePyramid> cv::gpu::createImagePyramid(InputArray, int, Stream&) { throw_no_cuda(); return Ptr<ImagePyramid>(); }
|
||||
|
||||
#else // HAVE_CUDA
|
||||
|
||||
@ -64,12 +65,11 @@ namespace cv { namespace gpu { namespace cudev
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream)
|
||||
void cv::gpu::pyrDown(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
using namespace cv::gpu::cudev::imgproc;
|
||||
|
||||
typedef void (*func_t)(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
|
||||
|
||||
static const func_t funcs[6][4] =
|
||||
{
|
||||
{pyrDown_gpu<uchar> , 0 /*pyrDown_gpu<uchar2>*/ , pyrDown_gpu<uchar3> , pyrDown_gpu<uchar4> },
|
||||
@ -80,12 +80,15 @@ void cv::gpu::pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream)
|
||||
{pyrDown_gpu<float> , 0 /*pyrDown_gpu<float2>*/ , pyrDown_gpu<float3> , pyrDown_gpu<float4> }
|
||||
};
|
||||
|
||||
CV_Assert(src.depth() <= CV_32F && src.channels() <= 4);
|
||||
GpuMat src = _src.getGpuMat();
|
||||
|
||||
CV_Assert( src.depth() <= CV_32F && src.channels() <= 4 );
|
||||
|
||||
const func_t func = funcs[src.depth()][src.channels() - 1];
|
||||
CV_Assert(func != 0);
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
dst.create((src.rows + 1) / 2, (src.cols + 1) / 2, src.type());
|
||||
_dst.create((src.rows + 1) / 2, (src.cols + 1) / 2, src.type());
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
func(src, dst, StreamAccessor::getStream(stream));
|
||||
}
|
||||
@ -102,12 +105,11 @@ namespace cv { namespace gpu { namespace cudev
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::pyrUp(const GpuMat& src, GpuMat& dst, Stream& stream)
|
||||
void cv::gpu::pyrUp(InputArray _src, OutputArray _dst, Stream& stream)
|
||||
{
|
||||
using namespace cv::gpu::cudev::imgproc;
|
||||
|
||||
typedef void (*func_t)(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
|
||||
|
||||
static const func_t funcs[6][4] =
|
||||
{
|
||||
{pyrUp_gpu<uchar> , 0 /*pyrUp_gpu<uchar2>*/ , pyrUp_gpu<uchar3> , pyrUp_gpu<uchar4> },
|
||||
@ -118,98 +120,124 @@ void cv::gpu::pyrUp(const GpuMat& src, GpuMat& dst, Stream& stream)
|
||||
{pyrUp_gpu<float> , 0 /*pyrUp_gpu<float2>*/ , pyrUp_gpu<float3> , pyrUp_gpu<float4> }
|
||||
};
|
||||
|
||||
CV_Assert(src.depth() <= CV_32F && src.channels() <= 4);
|
||||
GpuMat src = _src.getGpuMat();
|
||||
|
||||
CV_Assert( src.depth() <= CV_32F && src.channels() <= 4 );
|
||||
|
||||
const func_t func = funcs[src.depth()][src.channels() - 1];
|
||||
CV_Assert(func != 0);
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
dst.create(src.rows * 2, src.cols * 2, src.type());
|
||||
_dst.create(src.rows * 2, src.cols * 2, src.type());
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
func(src, dst, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// ImagePyramid
|
||||
|
||||
void cv::gpu::ImagePyramid::build(const GpuMat& img, int numLayers, Stream& stream)
|
||||
#ifdef HAVE_OPENCV_GPULEGACY
|
||||
|
||||
namespace
|
||||
{
|
||||
class ImagePyramidImpl : public ImagePyramid
|
||||
{
|
||||
public:
|
||||
ImagePyramidImpl(InputArray img, int nLayers, Stream& stream);
|
||||
|
||||
void getLayer(OutputArray outImg, Size outRoi, Stream& stream = Stream::Null()) const;
|
||||
|
||||
private:
|
||||
GpuMat layer0_;
|
||||
std::vector<GpuMat> pyramid_;
|
||||
int nLayers_;
|
||||
};
|
||||
|
||||
ImagePyramidImpl::ImagePyramidImpl(InputArray _img, int numLayers, Stream& stream)
|
||||
{
|
||||
GpuMat img = _img.getGpuMat();
|
||||
|
||||
CV_Assert( img.depth() <= CV_32F && img.channels() <= 4 );
|
||||
|
||||
img.copyTo(layer0_, stream);
|
||||
|
||||
Size szLastLayer = img.size();
|
||||
nLayers_ = 1;
|
||||
|
||||
if (numLayers <= 0)
|
||||
numLayers = 255; // it will cut-off when any of the dimensions goes 1
|
||||
|
||||
pyramid_.resize(numLayers);
|
||||
|
||||
for (int i = 0; i < numLayers - 1; ++i)
|
||||
{
|
||||
Size szCurLayer(szLastLayer.width / 2, szLastLayer.height / 2);
|
||||
|
||||
if (szCurLayer.width == 0 || szCurLayer.height == 0)
|
||||
break;
|
||||
|
||||
ensureSizeIsEnough(szCurLayer, img.type(), pyramid_[i]);
|
||||
nLayers_++;
|
||||
|
||||
const GpuMat& prevLayer = i == 0 ? layer0_ : pyramid_[i - 1];
|
||||
|
||||
cudev::pyramid::downsampleX2(prevLayer, pyramid_[i], img.depth(), img.channels(), StreamAccessor::getStream(stream));
|
||||
|
||||
szLastLayer = szCurLayer;
|
||||
}
|
||||
}
|
||||
|
||||
void ImagePyramidImpl::getLayer(OutputArray _outImg, Size outRoi, Stream& stream) const
|
||||
{
|
||||
CV_Assert( outRoi.width <= layer0_.cols && outRoi.height <= layer0_.rows && outRoi.width > 0 && outRoi.height > 0 );
|
||||
|
||||
ensureSizeIsEnough(outRoi, layer0_.type(), _outImg);
|
||||
GpuMat outImg = _outImg.getGpuMat();
|
||||
|
||||
if (outRoi.width == layer0_.cols && outRoi.height == layer0_.rows)
|
||||
{
|
||||
layer0_.copyTo(outImg, stream);
|
||||
return;
|
||||
}
|
||||
|
||||
float lastScale = 1.0f;
|
||||
float curScale;
|
||||
GpuMat lastLayer = layer0_;
|
||||
GpuMat curLayer;
|
||||
|
||||
for (int i = 0; i < nLayers_ - 1; ++i)
|
||||
{
|
||||
curScale = lastScale * 0.5f;
|
||||
curLayer = pyramid_[i];
|
||||
|
||||
if (outRoi.width == curLayer.cols && outRoi.height == curLayer.rows)
|
||||
{
|
||||
curLayer.copyTo(outImg, stream);
|
||||
}
|
||||
|
||||
if (outRoi.width >= curLayer.cols && outRoi.height >= curLayer.rows)
|
||||
break;
|
||||
|
||||
lastScale = curScale;
|
||||
lastLayer = curLayer;
|
||||
}
|
||||
|
||||
cudev::pyramid::interpolateFrom1(lastLayer, outImg, outImg.depth(), outImg.channels(), StreamAccessor::getStream(stream));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Ptr<ImagePyramid> cv::gpu::createImagePyramid(InputArray img, int nLayers, Stream& stream)
|
||||
{
|
||||
#ifndef HAVE_OPENCV_GPULEGACY
|
||||
(void) img;
|
||||
(void) numLayers;
|
||||
(void) stream;
|
||||
throw_no_cuda();
|
||||
return Ptr<ImagePyramid>();
|
||||
#else
|
||||
CV_Assert(img.depth() <= CV_32F && img.channels() <= 4);
|
||||
|
||||
layer0_ = img;
|
||||
Size szLastLayer = img.size();
|
||||
nLayers_ = 1;
|
||||
|
||||
if (numLayers <= 0)
|
||||
numLayers = 255; //it will cut-off when any of the dimensions goes 1
|
||||
|
||||
pyramid_.resize(numLayers);
|
||||
|
||||
for (int i = 0; i < numLayers - 1; ++i)
|
||||
{
|
||||
Size szCurLayer(szLastLayer.width / 2, szLastLayer.height / 2);
|
||||
|
||||
if (szCurLayer.width == 0 || szCurLayer.height == 0)
|
||||
break;
|
||||
|
||||
ensureSizeIsEnough(szCurLayer, img.type(), pyramid_[i]);
|
||||
nLayers_++;
|
||||
|
||||
const GpuMat& prevLayer = i == 0 ? layer0_ : pyramid_[i - 1];
|
||||
|
||||
cudev::pyramid::downsampleX2(prevLayer, pyramid_[i], img.depth(), img.channels(), StreamAccessor::getStream(stream));
|
||||
|
||||
szLastLayer = szCurLayer;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::gpu::ImagePyramid::getLayer(GpuMat& outImg, Size outRoi, Stream& stream) const
|
||||
{
|
||||
#ifndef HAVE_OPENCV_GPULEGACY
|
||||
(void) outImg;
|
||||
(void) outRoi;
|
||||
(void) stream;
|
||||
throw_no_cuda();
|
||||
#else
|
||||
CV_Assert(outRoi.width <= layer0_.cols && outRoi.height <= layer0_.rows && outRoi.width > 0 && outRoi.height > 0);
|
||||
|
||||
ensureSizeIsEnough(outRoi, layer0_.type(), outImg);
|
||||
|
||||
if (outRoi.width == layer0_.cols && outRoi.height == layer0_.rows)
|
||||
{
|
||||
layer0_.copyTo(outImg, stream);
|
||||
}
|
||||
|
||||
float lastScale = 1.0f;
|
||||
float curScale;
|
||||
GpuMat lastLayer = layer0_;
|
||||
GpuMat curLayer;
|
||||
|
||||
for (int i = 0; i < nLayers_ - 1; ++i)
|
||||
{
|
||||
curScale = lastScale * 0.5f;
|
||||
curLayer = pyramid_[i];
|
||||
|
||||
if (outRoi.width == curLayer.cols && outRoi.height == curLayer.rows)
|
||||
{
|
||||
curLayer.copyTo(outImg, stream);
|
||||
}
|
||||
|
||||
if (outRoi.width >= curLayer.cols && outRoi.height >= curLayer.rows)
|
||||
break;
|
||||
|
||||
lastScale = curScale;
|
||||
lastLayer = curLayer;
|
||||
}
|
||||
|
||||
cudev::pyramid::interpolateFrom1(lastLayer, outImg, outImg.depth(), outImg.channels(), StreamAccessor::getStream(stream));
|
||||
return new ImagePyramidImpl(img, nLayers, stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@
|
||||
|
||||
#if !defined HAVE_CUDA || defined(CUDA_DISABLER)
|
||||
|
||||
void cv::gpu::remap(const GpuMat&, GpuMat&, const GpuMat&, const GpuMat&, int, int, Scalar, Stream&){ throw_no_cuda(); }
|
||||
void cv::gpu::remap(InputArray, OutputArray, InputArray, InputArray, int, int, Scalar, Stream&){ throw_no_cuda(); }
|
||||
|
||||
#else // HAVE_CUDA
|
||||
|
||||
@ -58,13 +58,12 @@ namespace cv { namespace gpu { namespace cudev
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap, int interpolation, int borderMode, Scalar borderValue, Stream& stream)
|
||||
void cv::gpu::remap(InputArray _src, OutputArray _dst, InputArray _xmap, InputArray _ymap, int interpolation, int borderMode, Scalar borderValue, Stream& stream)
|
||||
{
|
||||
using namespace cv::gpu::cudev::imgproc;
|
||||
|
||||
typedef void (*func_t)(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, PtrStepSzf xmap, PtrStepSzf ymap, PtrStepSzb dst, int interpolation,
|
||||
int borderMode, const float* borderValue, cudaStream_t stream, bool cc20);
|
||||
|
||||
static const func_t funcs[6][4] =
|
||||
{
|
||||
{remap_gpu<uchar> , 0 /*remap_gpu<uchar2>*/ , remap_gpu<uchar3> , remap_gpu<uchar4> },
|
||||
@ -75,15 +74,21 @@ void cv::gpu::remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const Gp
|
||||
{remap_gpu<float> , 0 /*remap_gpu<float2>*/ , remap_gpu<float3> , remap_gpu<float4> }
|
||||
};
|
||||
|
||||
CV_Assert(src.depth() <= CV_32F && src.channels() <= 4);
|
||||
CV_Assert(xmap.type() == CV_32F && ymap.type() == CV_32F && xmap.size() == ymap.size());
|
||||
CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC);
|
||||
CV_Assert(borderMode == BORDER_REFLECT101 || borderMode == BORDER_REPLICATE || borderMode == BORDER_CONSTANT || borderMode == BORDER_REFLECT || borderMode == BORDER_WRAP);
|
||||
GpuMat src = _src.getGpuMat();
|
||||
GpuMat xmap = _xmap.getGpuMat();
|
||||
GpuMat ymap = _ymap.getGpuMat();
|
||||
|
||||
CV_Assert( src.depth() <= CV_32F && src.channels() <= 4 );
|
||||
CV_Assert( xmap.type() == CV_32F && ymap.type() == CV_32F && xmap.size() == ymap.size() );
|
||||
CV_Assert( interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC );
|
||||
CV_Assert( borderMode == BORDER_REFLECT101 || borderMode == BORDER_REPLICATE || borderMode == BORDER_CONSTANT || borderMode == BORDER_REFLECT || borderMode == BORDER_WRAP );
|
||||
|
||||
const func_t func = funcs[src.depth()][src.channels() - 1];
|
||||
CV_Assert(func != 0);
|
||||
if (!func)
|
||||
CV_Error(Error::StsUnsupportedFormat, "Unsupported input type");
|
||||
|
||||
dst.create(xmap.size(), src.type());
|
||||
_dst.create(xmap.size(), src.type());
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
Scalar_<float> borderValueFloat;
|
||||
borderValueFloat = borderValue;
|
||||
|
@ -44,7 +44,7 @@
|
||||
|
||||
#if !defined HAVE_CUDA || defined(CUDA_DISABLER)
|
||||
|
||||
void cv::gpu::resize(const GpuMat&, GpuMat&, Size, double, double, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::resize(InputArray, OutputArray, Size, double, double, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
#else // HAVE_CUDA
|
||||
|
||||
@ -58,30 +58,34 @@ namespace cv { namespace gpu { namespace cudev
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx, double fy, int interpolation, Stream& s)
|
||||
void cv::gpu::resize(InputArray _src, OutputArray _dst, Size dsize, double fx, double fy, int interpolation, Stream& _stream)
|
||||
{
|
||||
CV_Assert(src.depth() <= CV_32F && src.channels() <= 4);
|
||||
CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR
|
||||
|| interpolation == INTER_CUBIC || interpolation == INTER_AREA);
|
||||
CV_Assert(!(dsize == Size()) || (fx > 0 && fy > 0));
|
||||
GpuMat src = _src.getGpuMat();
|
||||
|
||||
CV_Assert( src.depth() <= CV_32F && src.channels() <= 4 );
|
||||
CV_Assert( interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC || interpolation == INTER_AREA );
|
||||
CV_Assert( !(dsize == Size()) || (fx > 0 && fy > 0) );
|
||||
|
||||
if (dsize == Size())
|
||||
{
|
||||
dsize = Size(saturate_cast<int>(src.cols * fx), saturate_cast<int>(src.rows * fy));
|
||||
}
|
||||
else
|
||||
{
|
||||
fx = static_cast<double>(dsize.width) / src.cols;
|
||||
fy = static_cast<double>(dsize.height) / src.rows;
|
||||
}
|
||||
if (dsize != dst.size())
|
||||
dst.create(dsize, src.type());
|
||||
|
||||
_dst.create(dsize, src.type());
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
if (dsize == src.size())
|
||||
{
|
||||
src.copyTo(dst, s);
|
||||
src.copyTo(dst, _stream);
|
||||
return;
|
||||
}
|
||||
|
||||
cudaStream_t stream = StreamAccessor::getStream(s);
|
||||
cudaStream_t stream = StreamAccessor::getStream(_stream);
|
||||
|
||||
Size wholeSize;
|
||||
Point ofs;
|
||||
|
@ -47,17 +47,17 @@ using namespace cv::gpu;
|
||||
|
||||
#if !defined HAVE_CUDA || defined(CUDA_DISABLER)
|
||||
|
||||
void cv::gpu::warpAffine(const GpuMat&, GpuMat&, const Mat&, Size, int, int, Scalar, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::buildWarpAffineMaps(const Mat&, bool, Size, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::warpAffine(InputArray, OutputArray, InputArray, Size, int, int, Scalar, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::buildWarpAffineMaps(InputArray, bool, Size, OutputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::warpPerspective(const GpuMat&, GpuMat&, const Mat&, Size, int, int, Scalar, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::buildWarpPerspectiveMaps(const Mat&, bool, Size, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::warpPerspective(InputArray, OutputArray, InputArray, Size, int, int, Scalar, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::buildWarpPerspectiveMaps(InputArray, bool, Size, OutputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::buildWarpPlaneMaps(Size, Rect, const Mat&, const Mat&, const Mat&, float, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::buildWarpCylindricalMaps(Size, Rect, const Mat&, const Mat&, float, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::buildWarpSphericalMaps(Size, Rect, const Mat&, const Mat&, float, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::buildWarpPlaneMaps(Size, Rect, InputArray, InputArray, InputArray, float, OutputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::buildWarpCylindricalMaps(Size, Rect, InputArray, InputArray, float, OutputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::buildWarpSphericalMaps(Size, Rect, InputArray, InputArray, float, OutputArray, OutputArray, Stream&) { throw_no_cuda(); }
|
||||
|
||||
void cv::gpu::rotate(const GpuMat&, GpuMat&, Size, double, double, double, int, Stream&) { throw_no_cuda(); }
|
||||
void cv::gpu::rotate(InputArray, OutputArray, Size, double, double, double, int, Stream&) { throw_no_cuda(); }
|
||||
|
||||
#else // HAVE_CUDA
|
||||
|
||||
@ -79,14 +79,19 @@ namespace cv { namespace gpu { namespace cudev
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream)
|
||||
void cv::gpu::buildWarpAffineMaps(InputArray _M, bool inverse, Size dsize, OutputArray _xmap, OutputArray _ymap, Stream& stream)
|
||||
{
|
||||
using namespace cv::gpu::cudev::imgproc;
|
||||
|
||||
CV_Assert(M.rows == 2 && M.cols == 3);
|
||||
Mat M = _M.getMat();
|
||||
|
||||
xmap.create(dsize, CV_32FC1);
|
||||
ymap.create(dsize, CV_32FC1);
|
||||
CV_Assert( M.rows == 2 && M.cols == 3 );
|
||||
|
||||
_xmap.create(dsize, CV_32FC1);
|
||||
_ymap.create(dsize, CV_32FC1);
|
||||
|
||||
GpuMat xmap = _xmap.getGpuMat();
|
||||
GpuMat ymap = _ymap.getGpuMat();
|
||||
|
||||
float coeffs[2 * 3];
|
||||
Mat coeffsMat(2, 3, CV_32F, (void*)coeffs);
|
||||
@ -103,14 +108,19 @@ void cv::gpu::buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat
|
||||
buildWarpAffineMaps_gpu(coeffs, xmap, ymap, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
void cv::gpu::buildWarpPerspectiveMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream)
|
||||
void cv::gpu::buildWarpPerspectiveMaps(InputArray _M, bool inverse, Size dsize, OutputArray _xmap, OutputArray _ymap, Stream& stream)
|
||||
{
|
||||
using namespace cv::gpu::cudev::imgproc;
|
||||
|
||||
CV_Assert(M.rows == 3 && M.cols == 3);
|
||||
Mat M = _M.getMat();
|
||||
|
||||
xmap.create(dsize, CV_32FC1);
|
||||
ymap.create(dsize, CV_32FC1);
|
||||
CV_Assert( M.rows == 3 && M.cols == 3 );
|
||||
|
||||
_xmap.create(dsize, CV_32FC1);
|
||||
_ymap.create(dsize, CV_32FC1);
|
||||
|
||||
GpuMat xmap = _xmap.getGpuMat();
|
||||
GpuMat ymap = _ymap.getGpuMat();
|
||||
|
||||
float coeffs[3 * 3];
|
||||
Mat coeffsMat(3, 3, CV_32F, (void*)coeffs);
|
||||
@ -174,17 +184,21 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
void cv::gpu::warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags, int borderMode, Scalar borderValue, Stream& s)
|
||||
void cv::gpu::warpAffine(InputArray _src, OutputArray _dst, InputArray _M, Size dsize, int flags, int borderMode, Scalar borderValue, Stream& stream)
|
||||
{
|
||||
CV_Assert(M.rows == 2 && M.cols == 3);
|
||||
GpuMat src = _src.getGpuMat();
|
||||
Mat M = _M.getMat();
|
||||
|
||||
int interpolation = flags & INTER_MAX;
|
||||
CV_Assert( M.rows == 2 && M.cols == 3 );
|
||||
|
||||
CV_Assert(src.depth() <= CV_32F && src.channels() <= 4);
|
||||
CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC);
|
||||
CV_Assert(borderMode == BORDER_REFLECT101 || borderMode == BORDER_REPLICATE || borderMode == BORDER_CONSTANT || borderMode == BORDER_REFLECT || borderMode == BORDER_WRAP);
|
||||
const int interpolation = flags & INTER_MAX;
|
||||
|
||||
dst.create(dsize, src.type());
|
||||
CV_Assert( src.depth() <= CV_32F && src.channels() <= 4 );
|
||||
CV_Assert( interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC );
|
||||
CV_Assert( borderMode == BORDER_REFLECT101 || borderMode == BORDER_REPLICATE || borderMode == BORDER_CONSTANT || borderMode == BORDER_REFLECT || borderMode == BORDER_WRAP );
|
||||
|
||||
_dst.create(dsize, src.type());
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
Size wholeSize;
|
||||
Point ofs;
|
||||
@ -258,7 +272,7 @@ void cv::gpu::warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsiz
|
||||
}
|
||||
};
|
||||
|
||||
dst.setTo(borderValue);
|
||||
dst.setTo(borderValue, stream);
|
||||
|
||||
double coeffs[2][3];
|
||||
Mat coeffsMat(2, 3, CV_64F, (void*)coeffs);
|
||||
@ -267,7 +281,7 @@ void cv::gpu::warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsiz
|
||||
const func_t func = funcs[(flags & WARP_INVERSE_MAP) != 0][src.depth()][src.channels() - 1];
|
||||
CV_Assert(func != 0);
|
||||
|
||||
func(src, dst, coeffs, interpolation, StreamAccessor::getStream(s));
|
||||
func(src, dst, coeffs, interpolation, StreamAccessor::getStream(stream));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -305,21 +319,25 @@ void cv::gpu::warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsiz
|
||||
borderValueFloat = borderValue;
|
||||
|
||||
func(src, PtrStepSzb(wholeSize.height, wholeSize.width, src.datastart, src.step), ofs.x, ofs.y, coeffs,
|
||||
dst, interpolation, borderMode, borderValueFloat.val, StreamAccessor::getStream(s), deviceSupports(FEATURE_SET_COMPUTE_20));
|
||||
dst, interpolation, borderMode, borderValueFloat.val, StreamAccessor::getStream(stream), deviceSupports(FEATURE_SET_COMPUTE_20));
|
||||
}
|
||||
}
|
||||
|
||||
void cv::gpu::warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags, int borderMode, Scalar borderValue, Stream& s)
|
||||
void cv::gpu::warpPerspective(InputArray _src, OutputArray _dst, InputArray _M, Size dsize, int flags, int borderMode, Scalar borderValue, Stream& stream)
|
||||
{
|
||||
CV_Assert(M.rows == 3 && M.cols == 3);
|
||||
GpuMat src = _src.getGpuMat();
|
||||
Mat M = _M.getMat();
|
||||
|
||||
int interpolation = flags & INTER_MAX;
|
||||
CV_Assert( M.rows == 3 && M.cols == 3 );
|
||||
|
||||
CV_Assert(src.depth() <= CV_32F && src.channels() <= 4);
|
||||
CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC);
|
||||
CV_Assert(borderMode == BORDER_REFLECT101 || borderMode == BORDER_REPLICATE || borderMode == BORDER_CONSTANT || borderMode == BORDER_REFLECT || borderMode == BORDER_WRAP);
|
||||
const int interpolation = flags & INTER_MAX;
|
||||
|
||||
dst.create(dsize, src.type());
|
||||
CV_Assert( src.depth() <= CV_32F && src.channels() <= 4 );
|
||||
CV_Assert( interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC );
|
||||
CV_Assert( borderMode == BORDER_REFLECT101 || borderMode == BORDER_REPLICATE || borderMode == BORDER_CONSTANT || borderMode == BORDER_REFLECT || borderMode == BORDER_WRAP) ;
|
||||
|
||||
_dst.create(dsize, src.type());
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
Size wholeSize;
|
||||
Point ofs;
|
||||
@ -393,7 +411,7 @@ void cv::gpu::warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size
|
||||
}
|
||||
};
|
||||
|
||||
dst.setTo(borderValue);
|
||||
dst.setTo(borderValue, stream);
|
||||
|
||||
double coeffs[3][3];
|
||||
Mat coeffsMat(3, 3, CV_64F, (void*)coeffs);
|
||||
@ -402,7 +420,7 @@ void cv::gpu::warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size
|
||||
const func_t func = funcs[(flags & WARP_INVERSE_MAP) != 0][src.depth()][src.channels() - 1];
|
||||
CV_Assert(func != 0);
|
||||
|
||||
func(src, dst, coeffs, interpolation, StreamAccessor::getStream(s));
|
||||
func(src, dst, coeffs, interpolation, StreamAccessor::getStream(stream));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -440,7 +458,7 @@ void cv::gpu::warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size
|
||||
borderValueFloat = borderValue;
|
||||
|
||||
func(src, PtrStepSzb(wholeSize.height, wholeSize.width, src.datastart, src.step), ofs.x, ofs.y, coeffs,
|
||||
dst, interpolation, borderMode, borderValueFloat.val, StreamAccessor::getStream(s), deviceSupports(FEATURE_SET_COMPUTE_20));
|
||||
dst, interpolation, borderMode, borderValueFloat.val, StreamAccessor::getStream(stream), deviceSupports(FEATURE_SET_COMPUTE_20));
|
||||
}
|
||||
}
|
||||
|
||||
@ -457,23 +475,30 @@ namespace cv { namespace gpu { namespace cudev
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::buildWarpPlaneMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, const Mat &T,
|
||||
float scale, GpuMat& map_x, GpuMat& map_y, Stream& stream)
|
||||
void cv::gpu::buildWarpPlaneMaps(Size src_size, Rect dst_roi, InputArray _K, InputArray _R, InputArray _T,
|
||||
float scale, OutputArray _map_x, OutputArray _map_y, Stream& stream)
|
||||
{
|
||||
(void)src_size;
|
||||
using namespace ::cv::gpu::cudev::imgproc;
|
||||
(void) src_size;
|
||||
|
||||
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(3,1) || T.size() == Size(1,3)) && T.type() == CV_32F && T.isContinuous());
|
||||
Mat K = _K.getMat();
|
||||
Mat R = _R.getMat();
|
||||
Mat T = _T.getMat();
|
||||
|
||||
CV_Assert( K.size() == Size(3,3) && K.type() == CV_32FC1 );
|
||||
CV_Assert( R.size() == Size(3,3) && R.type() == CV_32FC1 );
|
||||
CV_Assert( (T.size() == Size(3,1) || T.size() == Size(1,3)) && T.type() == CV_32FC1 && T.isContinuous() );
|
||||
|
||||
Mat K_Rinv = K * R.t();
|
||||
Mat R_Kinv = R * K.inv();
|
||||
CV_Assert(K_Rinv.isContinuous());
|
||||
CV_Assert(R_Kinv.isContinuous());
|
||||
CV_Assert( K_Rinv.isContinuous() );
|
||||
CV_Assert( R_Kinv.isContinuous() );
|
||||
|
||||
_map_x.create(dst_roi.size(), CV_32FC1);
|
||||
_map_y.create(dst_roi.size(), CV_32FC1);
|
||||
|
||||
GpuMat map_x = _map_x.getGpuMat();
|
||||
GpuMat map_y = _map_y.getGpuMat();
|
||||
|
||||
map_x.create(dst_roi.size(), CV_32F);
|
||||
map_y.create(dst_roi.size(), CV_32F);
|
||||
cudev::imgproc::buildWarpPlaneMaps(dst_roi.tl().x, dst_roi.tl().y, map_x, map_y, K_Rinv.ptr<float>(), R_Kinv.ptr<float>(),
|
||||
T.ptr<float>(), scale, StreamAccessor::getStream(stream));
|
||||
}
|
||||
@ -491,22 +516,28 @@ namespace cv { namespace gpu { namespace cudev
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::buildWarpCylindricalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, float scale,
|
||||
GpuMat& map_x, GpuMat& map_y, Stream& stream)
|
||||
void cv::gpu::buildWarpCylindricalMaps(Size src_size, Rect dst_roi, InputArray _K, InputArray _R, float scale,
|
||||
OutputArray _map_x, OutputArray _map_y, Stream& stream)
|
||||
{
|
||||
(void)src_size;
|
||||
using namespace ::cv::gpu::cudev::imgproc;
|
||||
(void) src_size;
|
||||
|
||||
CV_Assert(K.size() == Size(3,3) && K.type() == CV_32F);
|
||||
CV_Assert(R.size() == Size(3,3) && R.type() == CV_32F);
|
||||
Mat K = _K.getMat();
|
||||
Mat R = _R.getMat();
|
||||
|
||||
CV_Assert( K.size() == Size(3,3) && K.type() == CV_32FC1 );
|
||||
CV_Assert( R.size() == Size(3,3) && R.type() == CV_32FC1 );
|
||||
|
||||
Mat K_Rinv = K * R.t();
|
||||
Mat R_Kinv = R * K.inv();
|
||||
CV_Assert(K_Rinv.isContinuous());
|
||||
CV_Assert(R_Kinv.isContinuous());
|
||||
CV_Assert( K_Rinv.isContinuous() );
|
||||
CV_Assert( R_Kinv.isContinuous() );
|
||||
|
||||
_map_x.create(dst_roi.size(), CV_32FC1);
|
||||
_map_y.create(dst_roi.size(), CV_32FC1);
|
||||
|
||||
GpuMat map_x = _map_x.getGpuMat();
|
||||
GpuMat map_y = _map_y.getGpuMat();
|
||||
|
||||
map_x.create(dst_roi.size(), CV_32F);
|
||||
map_y.create(dst_roi.size(), CV_32F);
|
||||
cudev::imgproc::buildWarpCylindricalMaps(dst_roi.tl().x, dst_roi.tl().y, map_x, map_y, K_Rinv.ptr<float>(), R_Kinv.ptr<float>(), scale, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
@ -524,22 +555,28 @@ namespace cv { namespace gpu { namespace cudev
|
||||
}
|
||||
}}}
|
||||
|
||||
void cv::gpu::buildWarpSphericalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, float scale,
|
||||
GpuMat& map_x, GpuMat& map_y, Stream& stream)
|
||||
void cv::gpu::buildWarpSphericalMaps(Size src_size, Rect dst_roi, InputArray _K, InputArray _R, float scale,
|
||||
OutputArray _map_x, OutputArray _map_y, Stream& stream)
|
||||
{
|
||||
(void)src_size;
|
||||
using namespace ::cv::gpu::cudev::imgproc;
|
||||
(void) src_size;
|
||||
|
||||
CV_Assert(K.size() == Size(3,3) && K.type() == CV_32F);
|
||||
CV_Assert(R.size() == Size(3,3) && R.type() == CV_32F);
|
||||
Mat K = _K.getMat();
|
||||
Mat R = _R.getMat();
|
||||
|
||||
CV_Assert( K.size() == Size(3,3) && K.type() == CV_32FC1 );
|
||||
CV_Assert( R.size() == Size(3,3) && R.type() == CV_32FC1 );
|
||||
|
||||
Mat K_Rinv = K * R.t();
|
||||
Mat R_Kinv = R * K.inv();
|
||||
CV_Assert(K_Rinv.isContinuous());
|
||||
CV_Assert(R_Kinv.isContinuous());
|
||||
CV_Assert( K_Rinv.isContinuous() );
|
||||
CV_Assert( R_Kinv.isContinuous() );
|
||||
|
||||
_map_x.create(dst_roi.size(), CV_32FC1);
|
||||
_map_y.create(dst_roi.size(), CV_32FC1);
|
||||
|
||||
GpuMat map_x = _map_x.getGpuMat();
|
||||
GpuMat map_y = _map_y.getGpuMat();
|
||||
|
||||
map_x.create(dst_roi.size(), CV_32F);
|
||||
map_y.create(dst_roi.size(), CV_32F);
|
||||
cudev::imgproc::buildWarpSphericalMaps(dst_roi.tl().x, dst_roi.tl().y, map_x, map_y, K_Rinv.ptr<float>(), R_Kinv.ptr<float>(), scale, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
@ -589,10 +626,9 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
void cv::gpu::rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift, double yShift, int interpolation, Stream& stream)
|
||||
void cv::gpu::rotate(InputArray _src, OutputArray _dst, Size dsize, double angle, double xShift, double yShift, int interpolation, Stream& stream)
|
||||
{
|
||||
typedef void (*func_t)(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift, double yShift, int interpolation, cudaStream_t stream);
|
||||
|
||||
static const func_t funcs[6][4] =
|
||||
{
|
||||
{NppRotate<CV_8U, nppiRotate_8u_C1R>::call, 0, NppRotate<CV_8U, nppiRotate_8u_C3R>::call, NppRotate<CV_8U, nppiRotate_8u_C4R>::call},
|
||||
@ -603,12 +639,16 @@ void cv::gpu::rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, d
|
||||
{NppRotate<CV_32F, nppiRotate_32f_C1R>::call, 0, NppRotate<CV_32F, nppiRotate_32f_C3R>::call, NppRotate<CV_32F, nppiRotate_32f_C4R>::call}
|
||||
};
|
||||
|
||||
CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
|
||||
CV_Assert(src.channels() == 1 || src.channels() == 3 || src.channels() == 4);
|
||||
CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC);
|
||||
GpuMat src = _src.getGpuMat();
|
||||
|
||||
dst.create(dsize, src.type());
|
||||
dst.setTo(Scalar::all(0));
|
||||
CV_Assert( src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F );
|
||||
CV_Assert( src.channels() == 1 || src.channels() == 3 || src.channels() == 4 );
|
||||
CV_Assert( interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC );
|
||||
|
||||
_dst.create(dsize, src.type());
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
dst.setTo(Scalar::all(0), stream);
|
||||
|
||||
funcs[src.depth()][src.channels() - 1](src, dst, dsize, angle, xShift, yShift, interpolation, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
@ -24,12 +24,11 @@ static void help()
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void convertAndResize(const T& src, T& gray, T& resized, double scale)
|
||||
static void convertAndResize(const Mat& src, Mat& gray, Mat& resized, double scale)
|
||||
{
|
||||
if (src.channels() == 3)
|
||||
{
|
||||
cvtColor( src, gray, COLOR_BGR2GRAY );
|
||||
cv::cvtColor( src, gray, COLOR_BGR2GRAY );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -40,7 +39,30 @@ void convertAndResize(const T& src, T& gray, T& resized, double scale)
|
||||
|
||||
if (scale != 1)
|
||||
{
|
||||
resize(gray, resized, sz);
|
||||
cv::resize(gray, resized, sz);
|
||||
}
|
||||
else
|
||||
{
|
||||
resized = gray;
|
||||
}
|
||||
}
|
||||
|
||||
static void convertAndResize(const GpuMat& src, GpuMat& gray, GpuMat& resized, double scale)
|
||||
{
|
||||
if (src.channels() == 3)
|
||||
{
|
||||
gpu::cvtColor( src, gray, COLOR_BGR2GRAY );
|
||||
}
|
||||
else
|
||||
{
|
||||
gray = src;
|
||||
}
|
||||
|
||||
Size sz(cvRound(gray.cols * scale), cvRound(gray.rows * scale));
|
||||
|
||||
if (scale != 1)
|
||||
{
|
||||
gpu::resize(gray, resized, sz);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user