Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
d44adcd6
Commit
d44adcd6
authored
Aug 26, 2013
by
Roman Donchenko
Committed by
OpenCV Buildbot
Aug 26, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1336 from jet47:gpu-resize
parents
7cefb6f5
21c4753f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
373 additions
and
288 deletions
+373
-288
resize.cu
modules/gpu/src/cuda/resize.cu
+342
-162
resize.cpp
modules/gpu/src/resize.cpp
+28
-82
test_resize.cpp
modules/gpu/test/test_resize.cpp
+3
-44
No files found.
modules/gpu/src/cuda/resize.cu
View file @
d44adcd6
...
@@ -42,261 +42,441 @@
...
@@ -42,261 +42,441 @@
#if !defined CUDA_DISABLER
#if !defined CUDA_DISABLER
#include "internal_shared.hpp"
#include <cfloat>
#include "opencv2/gpu/device/common.hpp"
#include "opencv2/gpu/device/border_interpolate.hpp"
#include "opencv2/gpu/device/border_interpolate.hpp"
#include "opencv2/gpu/device/vec_traits.hpp"
#include "opencv2/gpu/device/vec_traits.hpp"
#include "opencv2/gpu/device/vec_math.hpp"
#include "opencv2/gpu/device/vec_math.hpp"
#include "opencv2/gpu/device/saturate_cast.hpp"
#include "opencv2/gpu/device/saturate_cast.hpp"
#include "opencv2/gpu/device/filters.hpp"
#include "opencv2/gpu/device/filters.hpp"
#include <cfloat>
#include <opencv2/gpu/device/scan.hpp>
namespace cv { namespace gpu { namespace device
namespace cv { namespace gpu { namespace device
{
{
namespace imgproc
// kernels
template <typename T> __global__ void resize_nearest(const PtrStep<T> src, PtrStepSz<T> dst, const float fy, const float fx)
{
{
template <typename Ptr2D, typename T> __global__ void resize(const Ptr2D src, float fx, float fy, PtrStepSz<T> dst)
const int dst_x = blockDim.x * blockIdx.x + threadIdx.x;
const int dst_y = blockDim.y * blockIdx.y + threadIdx.y;
if (dst_x < dst.cols && dst_y < dst.rows)
{
{
const
int x = blockDim.x * blockIdx.x + threadIdx.
x;
const
float src_x = dst_x * f
x;
const
int y = blockDim.y * blockIdx.y + threadIdx.
y;
const
float src_y = dst_y * f
y;
if (x < dst.cols && y < dst.rows)
dst(dst_y, dst_x) = src(__float2int_rz(src_y), __float2int_rz(src_x));
}
}
template <typename T> __global__ void resize_linear(const PtrStepSz<T> src, PtrStepSz<T> dst, const float fy, const float fx)
{
typedef typename TypeVec<float, VecTraits<T>::cn>::vec_type work_type;
const int dst_x = blockDim.x * blockIdx.x + threadIdx.x;
const int dst_y = blockDim.y * blockIdx.y + threadIdx.y;
if (dst_x < dst.cols && dst_y < dst.rows)
{
{
const float xcoo =
x * fx;
const float src_x = dst_
x * fx;
const float ycoo =
y * fy;
const float src_y = dst_
y * fy;
dst(y, x) = saturate_cast<T>(src(ycoo, xcoo));
work_type out = VecTraits<work_type>::all(0);
const int x1 = __float2int_rd(src_x);
const int y1 = __float2int_rd(src_y);
const int x2 = x1 + 1;
const int y2 = y1 + 1;
const int x2_read = ::min(x2, src.cols - 1);
const int y2_read = ::min(y2, src.rows - 1);
T src_reg = src(y1, x1);
out = out + src_reg * ((x2 - src_x) * (y2 - src_y));
src_reg = src(y1, x2_read);
out = out + src_reg * ((src_x - x1) * (y2 - src_y));
src_reg = src(y2_read, x1);
out = out + src_reg * ((x2 - src_x) * (src_y - y1));
src_reg = src(y2_read, x2_read);
out = out + src_reg * ((src_x - x1) * (src_y - y1));
dst(dst_y, dst_x) = saturate_cast<T>(out);
}
}
}
}
template <typename Ptr2D, typename T> __global__ void resize_area(const Ptr2D src, float fx, float fy, PtrStepSz<T> dst)
template <class Ptr2D, typename T> __global__ void resize(const Ptr2D src, PtrStepSz<T> dst, const float fy, const float fx)
{
const int dst_x = blockDim.x * blockIdx.x + threadIdx.x;
const int dst_y = blockDim.y * blockIdx.y + threadIdx.y;
if (dst_x < dst.cols && dst_y < dst.rows)
{
const float src_x = dst_x * fx;
const float src_y = dst_y * fy;
dst(dst_y, dst_x) = src(src_y, src_x);
}
}
template <typename Ptr2D, typename T> __global__ void resize_area(const Ptr2D src, PtrStepSz<T> dst)
{
{
const int x = blockDim.x * blockIdx.x + threadIdx.x;
const int x = blockDim.x * blockIdx.x + threadIdx.x;
const int y = blockDim.y * blockIdx.y + threadIdx.y;
const int y = blockDim.y * blockIdx.y + threadIdx.y;
if (x < dst.cols && y < dst.rows)
if (x < dst.cols && y < dst.rows)
{
{
dst(y, x) = saturate_cast<T>(src(y, x)
);
dst(y, x) = src(y, x
);
}
}
}
}
template <template <typename> class Filter, typename T> struct ResizeDispatcherStream
// textures
{
static void call(PtrStepSz<T> src, float fx, float fy, PtrStepSz<T> dst, cudaStream_t stream)
{
dim3 block(32, 8);
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
BrdReplicate<T> brd(src.rows, src.cols);
template <typename T> struct TextureAccessor;
BorderReader< PtrStep<T>, BrdReplicate<T> > brdSrc(src, brd);
Filter< BorderReader< PtrStep<T>, BrdReplicate<T> > > filteredSrc(brdSrc, fx, fy);
resize<<<grid, block, 0, stream>>>(filteredSrc, fx, fy, dst);
#define OPENCV_GPU_IMPLEMENT_RESIZE_TEX(type) \
cudaSafeCall( cudaGetLastError() );
texture<type, cudaTextureType2D, cudaReadModeElementType> tex_resize_##type (0, cudaFilterModePoint, cudaAddressModeClamp); \
}
template <> struct TextureAccessor<type> \
{ \
typedef type elem_type; \
typedef int index_type; \
int xoff; \
int yoff; \
__device__ __forceinline__ elem_type operator ()(index_type y, index_type x) const \
{ \
return tex2D(tex_resize_##type, x + xoff, y + yoff); \
} \
__host__ static void bind(const PtrStepSz<type>& mat) \
{ \
bindTexture(&tex_resize_##type, mat); \
} \
};
};
template <typename T> struct ResizeDispatcherStream<AreaFilter, T>
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(uchar)
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(uchar4)
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(ushort)
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(ushort4)
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(short)
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(short4)
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(float)
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(float4)
#undef OPENCV_GPU_IMPLEMENT_RESIZE_TEX
template <typename T>
TextureAccessor<T> texAccessor(const PtrStepSz<T>& mat, int yoff, int xoff)
{
{
static void call(PtrStepSz<T> src, float fx, float fy, PtrStepSz<T> dst, cudaStream_t stream)
TextureAccessor<T>::bind(mat);
TextureAccessor<T> t;
t.xoff = xoff;
t.yoff = yoff;
return t;
}
// callers for nearest interpolation
template <typename T>
void call_resize_nearest_glob(const PtrStepSz<T>& src, const PtrStepSz<T>& dst, float fy, float fx, cudaStream_t stream)
{
{
dim3 block(32, 8);
const
dim3 block(32, 8);
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
const
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
BrdConstant<T> brd(src.rows, src.cols);
resize_nearest<<<grid, block, 0, stream>>>(src, dst, fy, fx);
BorderReader< PtrStep<T>, BrdConstant<T> > brdSrc(src, brd);
AreaFilter< BorderReader< PtrStep<T>, BrdConstant<T> > > filteredSrc(brdSrc, fx, fy);
resize_area<<<grid, block, 0, stream>>>(filteredSrc, fx, fy, dst);
cudaSafeCall( cudaGetLastError() );
cudaSafeCall( cudaGetLastError() );
if (stream == 0)
if (stream == 0)
cudaSafeCall( cudaDeviceSynchronize() );
cudaSafeCall( cudaDeviceSynchronize() );
}
}
};
template <typename T> struct ResizeDispatcherStream<IntegerAreaFilter, T>
template <typename T>
void call_resize_nearest_tex(const PtrStepSz<T>& src, const PtrStepSz<T>& srcWhole, int yoff, int xoff, const PtrStepSz<T>& dst, float fy, float fx)
{
{
static void call(PtrStepSz<T> src, float fx, float fy, PtrStepSz<T> dst, cudaStream_t stream)
const dim3 block(32, 8);
const dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
resize<<<grid, block>>>(texAccessor(srcWhole, yoff, xoff), dst, fy, fx);
cudaSafeCall( cudaGetLastError() );
cudaSafeCall( cudaDeviceSynchronize() );
}
// callers for linear interpolation
template <typename T>
void call_resize_linear_glob(const PtrStepSz<T>& src, const PtrStepSz<T>& dst, float fy, float fx, cudaStream_t stream)
{
{
dim3 block(32, 8);
const dim3 block(32, 8);
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
const dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
BrdConstant<T> brd(src.rows, src.cols);
BorderReader< PtrStep<T>, BrdConstant<T> > brdSrc(src, brd);
resize_linear<<<grid, block>>>(src, dst, fy, fx);
IntegerAreaFilter< BorderReader< PtrStep<T>, BrdConstant<T> > > filteredSrc(brdSrc, fx, fy);
resize_area<<<grid, block, 0, stream>>>(filteredSrc, fx, fy, dst);
cudaSafeCall( cudaGetLastError() );
cudaSafeCall( cudaGetLastError() );
if (stream == 0)
if (stream == 0)
cudaSafeCall( cudaDeviceSynchronize() );
cudaSafeCall( cudaDeviceSynchronize() );
}
}
};
template <template <typename> class Filter, typename T> struct ResizeDispatcherNonStream
template <typename T>
void call_resize_linear_tex(const PtrStepSz<T>& src, const PtrStepSz<T>& srcWhole, int yoff, int xoff, const PtrStepSz<T>& dst, float fy, float fx)
{
const dim3 block(32, 8);
const dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
if (srcWhole.data == src.data)
{
{
static void call(PtrStepSz<T> src, PtrStepSz<T> srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSz<T> dst)
TextureAccessor<T> texSrc = texAccessor(src, 0, 0);
LinearFilter< TextureAccessor<T> > filteredSrc(texSrc);
resize<<<grid, block>>>(filteredSrc, dst, fy, fx);
}
else
{
{
(void)srcWhole;
TextureAccessor<T> texSrc = texAccessor(srcWhole, yoff, xoff);
(void)xoff;
(void)yoff;
BrdReplicate<T> brd(src.rows, src.cols);
BorderReader<TextureAccessor<T>, BrdReplicate<T> > brdSrc(texSrc, brd);
LinearFilter< BorderReader<TextureAccessor<T>, BrdReplicate<T> > > filteredSrc(brdSrc);
resize<<<grid, block>>>(filteredSrc, dst, fy, fx);
}
cudaSafeCall( cudaGetLastError() );
cudaSafeCall( cudaDeviceSynchronize() );
}
dim3 block(32, 8);
// callers for cubic interpolation
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
template <typename T>
void call_resize_cubic_glob(const PtrStepSz<T>& src, const PtrStepSz<T>& dst, float fy, float fx, cudaStream_t stream)
{
const dim3 block(32, 8);
const dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
BrdReplicate<T> brd(src.rows, src.cols);
BrdReplicate<T> brd(src.rows, src.cols);
BorderReader< PtrStep<T>, BrdReplicate<T> > brdSrc(src, brd);
BorderReader< PtrStep<T>, BrdReplicate<T> > brdSrc(src, brd);
Filter< BorderReader< PtrStep<T>, BrdReplicate<T> > > filteredSrc(brdSrc);
Cubic
Filter< BorderReader< PtrStep<T>, BrdReplicate<T> > > filteredSrc(brdSrc);
resize<<<grid, block>>>(filteredSrc, fx, fy, dst
);
resize<<<grid, block, 0, stream>>>(filteredSrc, dst, fy, fx
);
cudaSafeCall( cudaGetLastError() );
cudaSafeCall( cudaGetLastError() );
if (stream == 0)
cudaSafeCall( cudaDeviceSynchronize() );
cudaSafeCall( cudaDeviceSynchronize() );
}
}
};
#define OPENCV_GPU_IMPLEMENT_RESIZE_TEX(type) \
template <typename T>
texture< type , cudaTextureType2D> tex_resize_ ## type (0, cudaFilterModePoint, cudaAddressModeClamp); \
void call_resize_cubic_tex(const PtrStepSz<T>& src, const PtrStepSz<T>& srcWhole, int yoff, int xoff, const PtrStepSz<T>& dst, float fy, float fx)
struct tex_resize_ ## type ## _reader \
{
{ \
const dim3 block(32, 8);
typedef type elem_type; \
const dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
typedef int index_type; \
const int xoff; \
const int yoff; \
__host__ tex_resize_ ## type ## _reader(int xoff_, int yoff_) : xoff(xoff_), yoff(yoff_) {} \
__device__ __forceinline__ elem_type operator ()(index_type y, index_type x) const \
{ \
return tex2D(tex_resize_ ## type, x + xoff, y + yoff); \
} \
}; \
template <template <typename> class Filter> struct ResizeDispatcherNonStream<Filter, type > \
{ \
static void call(PtrStepSz< type > src, PtrStepSz< type > srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSz< type > dst) \
{ \
dim3 block(32, 8); \
dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y)); \
bindTexture(&tex_resize_ ## type, srcWhole); \
tex_resize_ ## type ## _reader texSrc(xoff, yoff); \
if (srcWhole.cols == src.cols && srcWhole.rows == src.rows) \
{ \
Filter<tex_resize_ ## type ## _reader> filteredSrc(texSrc); \
resize<<<grid, block>>>(filteredSrc, fx, fy, dst); \
} \
else \
{ \
BrdReplicate< type > brd(src.rows, src.cols); \
BorderReader<tex_resize_ ## type ## _reader, BrdReplicate< type > > brdSrc(texSrc, brd); \
Filter< BorderReader<tex_resize_ ## type ## _reader, BrdReplicate< type > > > filteredSrc(brdSrc); \
resize<<<grid, block>>>(filteredSrc, fx, fy, dst); \
} \
cudaSafeCall( cudaGetLastError() ); \
cudaSafeCall( cudaDeviceSynchronize() ); \
} \
};
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(uchar)
if (srcWhole.data == src.data)
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(uchar4)
{
TextureAccessor<T> texSrc = texAccessor(src, 0, 0);
CubicFilter< TextureAccessor<T> > filteredSrc(texSrc);
//OPENCV_GPU_IMPLEMENT_RESIZE_TEX(schar)
resize<<<grid, block>>>(filteredSrc, dst, fy, fx);
//OPENCV_GPU_IMPLEMENT_RESIZE_TEX(char4)
}
else
{
TextureAccessor<T> texSrc = texAccessor(srcWhole, yoff, xoff);
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(ushort)
BrdReplicate<T> brd(src.rows, src.cols);
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(ushort4)
BorderReader<TextureAccessor<T>, BrdReplicate<T> > brdSrc(texSrc, brd);
CubicFilter< BorderReader<TextureAccessor<T>, BrdReplicate<T> > > filteredSrc(brdSrc);
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(short)
resize<<<grid, block>>>(filteredSrc, dst, fy, fx);
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(short4)
}
//OPENCV_GPU_IMPLEMENT_RESIZE_TEX(int)
cudaSafeCall( cudaGetLastError() );
//OPENCV_GPU_IMPLEMENT_RESIZE_TEX(int4)
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(float)
cudaSafeCall( cudaDeviceSynchronize() );
OPENCV_GPU_IMPLEMENT_RESIZE_TEX(float4)
}
#undef OPENCV_GPU_IMPLEMENT_RESIZE_TEX
// ResizeNearestDispatcher
template <template <typename> class Filter, typename T> struct Resize
Dispatcher
template <typename T> struct ResizeNearest
Dispatcher
{
{
static void call(PtrStepSz<T> src, PtrStepSz<T> srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSz<T> dst
, cudaStream_t stream)
static void call(const PtrStepSz<T>& src, const PtrStepSz<T>& srcWhole, int yoff, int xoff, const PtrStepSz<T>& dst, float fy, float fx
, cudaStream_t stream)
{
{
if (stream == 0)
call_resize_nearest_glob(src, dst, fy, fx, stream);
ResizeDispatcherNonStream<Filter, T>::call(src, srcWhole, xoff, yoff, fx, fy, dst);
}
};
template <typename T> struct SelectImplForNearest
{
static void call(const PtrStepSz<T>& src, const PtrStepSz<T>& srcWhole, int yoff, int xoff, const PtrStepSz<T>& dst, float fy, float fx, cudaStream_t stream)
{
if (stream)
call_resize_nearest_glob(src, dst, fy, fx, stream);
else
{
if (fx > 1 || fy > 1)
call_resize_nearest_glob(src, dst, fy, fx, 0);
else
else
ResizeDispatcherStream<Filter, T>::call(src, fx, fy, dst, stream);
call_resize_nearest_tex(src, srcWhole, yoff, xoff, dst, fy, fx);
}
}
}
};
};
template <typename T> struct ResizeDispatcher<AreaFilter, T>
template <> struct ResizeNearestDispatcher<uchar> : SelectImplForNearest<uchar> {};
template <> struct ResizeNearestDispatcher<uchar4> : SelectImplForNearest<uchar4> {};
template <> struct ResizeNearestDispatcher<ushort> : SelectImplForNearest<ushort> {};
template <> struct ResizeNearestDispatcher<ushort4> : SelectImplForNearest<ushort4> {};
template <> struct ResizeNearestDispatcher<short> : SelectImplForNearest<short> {};
template <> struct ResizeNearestDispatcher<short4> : SelectImplForNearest<short4> {};
template <> struct ResizeNearestDispatcher<float> : SelectImplForNearest<float> {};
template <> struct ResizeNearestDispatcher<float4> : SelectImplForNearest<float4> {};
// ResizeLinearDispatcher
template <typename T> struct ResizeLinearDispatcher
{
{
static void call(PtrStepSz<T> src, PtrStepSz<T> srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSz<T> dst
, cudaStream_t stream)
static void call(const PtrStepSz<T>& src, const PtrStepSz<T>& srcWhole, int yoff, int xoff, const PtrStepSz<T>& dst, float fy, float fx
, cudaStream_t stream)
{
{
(void)srcWhole;
call_resize_linear_glob(src, dst, fy, fx, stream);
(void)xoff;
}
(void)yoff;
};
int iscale_x = (int)round(fx);
int iscale_y = (int)round(fy);
if( std::abs(fx - iscale_x) < FLT_MIN && std::abs(fy - iscale_y) < FLT_MIN)
template <typename T> struct SelectImplForLinear
ResizeDispatcherStream<IntegerAreaFilter, T>::call(src, fx, fy, dst, stream);
{
static void call(const PtrStepSz<T>& src, const PtrStepSz<T>& srcWhole, int yoff, int xoff, const PtrStepSz<T>& dst, float fy, float fx, cudaStream_t stream)
{
if (stream)
call_resize_linear_glob(src, dst, fy, fx, stream);
else
{
if (fx > 1 || fy > 1)
call_resize_linear_glob(src, dst, fy, fx, 0);
else
else
ResizeDispatcherStream<AreaFilter, T>::call(src, fx, fy, dst, stream);
call_resize_linear_tex(src, srcWhole, yoff, xoff, dst, fy, fx);
}
}
}
};
};
template <typename T> void resize_gpu(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy,
template <> struct ResizeLinearDispatcher<uchar> : SelectImplForLinear<uchar> {};
PtrStepSzb dst, int interpolation, cudaStream_t stream)
template <> struct ResizeLinearDispatcher<uchar4> : SelectImplForLinear<uchar4> {};
{
typedef void (*caller_t)(PtrStepSz<T> src, PtrStepSz<T> srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSz<T> dst, cudaStream_t stream);
template <> struct ResizeLinearDispatcher<ushort> : SelectImplForLinear<ushort> {};
template <> struct ResizeLinearDispatcher<ushort4> : SelectImplForLinear<ushort4> {};
template <> struct ResizeLinearDispatcher<short> : SelectImplForLinear<short> {};
template <> struct ResizeLinearDispatcher<short4> : SelectImplForLinear<short4> {};
static const caller_t callers[4] =
template <> struct ResizeLinearDispatcher<float> : SelectImplForLinear<float> {};
template <> struct ResizeLinearDispatcher<float4> : SelectImplForLinear<float4> {};
// ResizeCubicDispatcher
template <typename T> struct ResizeCubicDispatcher
{
static void call(const PtrStepSz<T>& src, const PtrStepSz<T>& srcWhole, int yoff, int xoff, const PtrStepSz<T>& dst, float fy, float fx, cudaStream_t stream)
{
{
ResizeDispatcher<PointFilter, T>::call,
call_resize_cubic_glob(src, dst, fy, fx, stream);
ResizeDispatcher<LinearFilter, T>::call,
}
ResizeDispatcher<CubicFilter, T>::call,
ResizeDispatcher<AreaFilter, T>::call
};
};
// chenge to linear if area interpolation upscaling
if (interpolation == 3 && (fx <= 1.f || fy <= 1.f))
interpolation = 1;
callers[interpolation](static_cast< PtrStepSz<T> >(src), static_cast< PtrStepSz<T> >(srcWhole), xoff, yoff, fx, fy,
template <typename T> struct SelectImplForCubic
static_cast< PtrStepSz<T> >(dst), stream);
{
static void call(const PtrStepSz<T>& src, const PtrStepSz<T>& srcWhole, int yoff, int xoff, const PtrStepSz<T>& dst, float fy, float fx, cudaStream_t stream)
{
if (stream)
call_resize_cubic_glob(src, dst, fy, fx, stream);
else
call_resize_cubic_tex(src, srcWhole, yoff, xoff, dst, fy, fx);
}
}
};
template void resize_gpu<uchar >(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template <> struct ResizeCubicDispatcher<uchar> : SelectImplForCubic<uchar> {};
//template void resize_gpu<uchar2>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template <> struct ResizeCubicDispatcher<uchar4> : SelectImplForCubic<uchar4> {};
template void resize_gpu<uchar3>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template void resize_gpu<uchar4>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<schar>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template <> struct ResizeCubicDispatcher<ushort> : SelectImplForCubic<ushort> {};
//template void resize_gpu<char2>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template <> struct ResizeCubicDispatcher<ushort4> : SelectImplForCubic<ushort4> {};
//template void resize_gpu<char3>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<char4>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template void resize_gpu<ushort >(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template <> struct ResizeCubicDispatcher<short> : SelectImplForCubic<short> {};
//template void resize_gpu<ushort2>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template <> struct ResizeCubicDispatcher<short4> : SelectImplForCubic<short4> {};
template void resize_gpu<ushort3>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template void resize_gpu<ushort4>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template void resize_gpu<short >(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template <> struct ResizeCubicDispatcher<float> : SelectImplForCubic<float> {};
//template void resize_gpu<short2>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template <> struct ResizeCubicDispatcher<float4> : SelectImplForCubic<float4> {};
template void resize_gpu<short3>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template void resize_gpu<short4>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int >(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
// ResizeAreaDispatcher
//template void resize_gpu<int2>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int3>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
//template void resize_gpu<int4>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template void resize_gpu<float >(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
template <typename T> struct ResizeAreaDispatcher
//template void resize_gpu<float2>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
{
template void resize_gpu<float3>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
static void call(const PtrStepSz<T>& src, const PtrStepSz<T>&, int, int, const PtrStepSz<T>& dst, float fy, float fx, cudaStream_t stream)
template void resize_gpu<float4>(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream);
{
const int iscale_x = (int) round(fx);
const int iscale_y = (int) round(fy);
template<typename T> struct scan_traits{};
const dim3 block(32, 8);
const dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y));
template<> struct scan_traits<uchar>
if (std::abs(fx - iscale_x) < FLT_MIN && std::abs(fy - iscale_y) < FLT_MIN)
{
{
typedef float scan_line_type;
BrdConstant<T> brd(src.rows, src.cols);
BorderReader< PtrStep<T>, BrdConstant<T> > brdSrc(src, brd);
IntegerAreaFilter< BorderReader< PtrStep<T>, BrdConstant<T> > > filteredSrc(brdSrc, fx, fy);
resize_area<<<grid, block, 0, stream>>>(filteredSrc, dst);
}
else
{
BrdConstant<T> brd(src.rows, src.cols);
BorderReader< PtrStep<T>, BrdConstant<T> > brdSrc(src, brd);
AreaFilter< BorderReader< PtrStep<T>, BrdConstant<T> > > filteredSrc(brdSrc, fx, fy);
resize_area<<<grid, block, 0, stream>>>(filteredSrc, dst);
}
cudaSafeCall( cudaGetLastError() );
if (stream == 0)
cudaSafeCall( cudaDeviceSynchronize() );
}
};
};
} // namespace imgproc
// resize
}}} // namespace cv { namespace gpu { namespace device
template <typename T> void resize(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream)
{
typedef void (*func_t)(const PtrStepSz<T>& src, const PtrStepSz<T>& srcWhole, int yoff, int xoff, const PtrStepSz<T>& dst, float fy, float fx, cudaStream_t stream);
static const func_t funcs[4] =
{
ResizeNearestDispatcher<T>::call,
ResizeLinearDispatcher<T>::call,
ResizeCubicDispatcher<T>::call,
ResizeAreaDispatcher<T>::call
};
// change to linear if area interpolation upscaling
if (interpolation == 3 && (fx <= 1.f || fy <= 1.f))
interpolation = 1;
funcs[interpolation](static_cast< PtrStepSz<T> >(src), static_cast< PtrStepSz<T> >(srcWhole), yoff, xoff, static_cast< PtrStepSz<T> >(dst), fy, fx, stream);
}
template void resize<uchar >(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<uchar3>(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<uchar4>(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<ushort >(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<ushort3>(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<ushort4>(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<short >(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<short3>(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<short4>(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<float >(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<float3>(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
template void resize<float4>(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
}}}
#endif /* CUDA_DISABLER */
#endif /* CUDA_DISABLER */
modules/gpu/src/resize.cpp
View file @
d44adcd6
...
@@ -44,119 +44,65 @@
...
@@ -44,119 +44,65 @@
#if !defined HAVE_CUDA || defined(CUDA_DISABLER)
#if !defined HAVE_CUDA || defined(CUDA_DISABLER)
void
cv
::
gpu
::
resize
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
Size
dsize
,
double
fx
,
double
fy
,
int
interpolation
,
Stream
&
s
)
void
cv
::
gpu
::
resize
(
const
GpuMat
&
,
GpuMat
&
,
Size
,
double
,
double
,
int
,
Stream
&
)
{
throw_nogpu
();
}
{
(
void
)
src
;
(
void
)
dst
;
(
void
)
dsize
;
(
void
)
fx
;
(
void
)
fy
;
(
void
)
interpolation
;
(
void
)
s
;
throw_nogpu
();
}
#else // HAVE_CUDA
#else // HAVE_CUDA
namespace
cv
{
namespace
gpu
{
namespace
device
namespace
cv
{
namespace
gpu
{
namespace
device
{
{
namespace
imgproc
{
template
<
typename
T
>
template
<
typename
T
>
void
resize_gpu
(
PtrStepSzb
src
,
PtrStepSzb
srcWhole
,
int
xoff
,
int
yoff
,
float
fx
,
float
fy
,
void
resize
(
const
PtrStepSzb
&
src
,
const
PtrStepSzb
&
srcWhole
,
int
yoff
,
int
xoff
,
const
PtrStepSzb
&
dst
,
float
fy
,
float
fx
,
int
interpolation
,
cudaStream_t
stream
);
PtrStepSzb
dst
,
int
interpolation
,
cudaStream_t
stream
);
}
}}}
}}}
void
cv
::
gpu
::
resize
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
Size
dsize
,
double
fx
,
double
fy
,
int
interpolation
,
Stream
&
s
)
void
cv
::
gpu
::
resize
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
Size
dsize
,
double
fx
,
double
fy
,
int
interpolation
,
Stream
&
s
tream
)
{
{
CV_Assert
(
src
.
depth
()
<=
CV_32F
&&
src
.
channels
()
<=
4
);
typedef
void
(
*
func_t
)(
const
PtrStepSzb
&
src
,
const
PtrStepSzb
&
srcWhole
,
int
yoff
,
int
xoff
,
const
PtrStepSzb
&
dst
,
float
fy
,
float
fx
,
int
interpolation
,
cudaStream_t
stream
);
CV_Assert
(
interpolation
==
INTER_NEAREST
||
interpolation
==
INTER_LINEAR
static
const
func_t
funcs
[
6
][
4
]
=
||
interpolation
==
INTER_CUBIC
||
interpolation
==
INTER_AREA
);
{
CV_Assert
(
!
(
dsize
==
Size
())
||
(
fx
>
0
&&
fy
>
0
));
{
device
::
resize
<
uchar
>
,
0
/*device::resize<uchar2>*/
,
device
::
resize
<
uchar3
>
,
device
::
resize
<
uchar4
>
},
{
0
/*device::resize<schar>*/
,
0
/*device::resize<char2>*/
,
0
/*device::resize<char3>*/
,
0
/*device::resize<char4>*/
},
{
device
::
resize
<
ushort
>
,
0
/*device::resize<ushort2>*/
,
device
::
resize
<
ushort3
>
,
device
::
resize
<
ushort4
>
},
{
device
::
resize
<
short
>
,
0
/*device::resize<short2>*/
,
device
::
resize
<
short3
>
,
device
::
resize
<
short4
>
},
{
0
/*device::resize<int>*/
,
0
/*device::resize<int2>*/
,
0
/*device::resize<int3>*/
,
0
/*device::resize<int4>*/
},
{
device
::
resize
<
float
>
,
0
/*device::resize<float2>*/
,
device
::
resize
<
float3
>
,
device
::
resize
<
float4
>
}
};
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
())
if
(
dsize
==
Size
())
{
dsize
=
Size
(
saturate_cast
<
int
>
(
src
.
cols
*
fx
),
saturate_cast
<
int
>
(
src
.
rows
*
fy
));
dsize
=
Size
(
saturate_cast
<
int
>
(
src
.
cols
*
fx
),
saturate_cast
<
int
>
(
src
.
rows
*
fy
));
}
else
else
{
{
fx
=
static_cast
<
double
>
(
dsize
.
width
)
/
src
.
cols
;
fx
=
static_cast
<
double
>
(
dsize
.
width
)
/
src
.
cols
;
fy
=
static_cast
<
double
>
(
dsize
.
height
)
/
src
.
rows
;
fy
=
static_cast
<
double
>
(
dsize
.
height
)
/
src
.
rows
;
}
}
if
(
dsize
!=
dst
.
size
())
dst
.
create
(
dsize
,
src
.
type
());
dst
.
create
(
dsize
,
src
.
type
());
if
(
dsize
==
src
.
size
())
if
(
dsize
==
src
.
size
())
{
{
if
(
s
)
if
(
s
tream
)
s
.
enqueueCopy
(
src
,
dst
);
s
tream
.
enqueueCopy
(
src
,
dst
);
else
else
src
.
copyTo
(
dst
);
src
.
copyTo
(
dst
);
return
;
return
;
}
}
cudaStream_t
stream
=
StreamAccessor
::
getStream
(
s
);
const
func_t
func
=
funcs
[
src
.
depth
()][
src
.
channels
()
-
1
];
if
(
!
func
)
CV_Error
(
CV_StsUnsupportedFormat
,
"Unsupported combination of source and destination types"
);
Size
wholeSize
;
Size
wholeSize
;
Point
ofs
;
Point
ofs
;
src
.
locateROI
(
wholeSize
,
ofs
);
src
.
locateROI
(
wholeSize
,
ofs
);
PtrStepSzb
wholeSrc
(
wholeSize
.
height
,
wholeSize
.
width
,
src
.
datastart
,
src
.
step
);
bool
useNpp
=
(
src
.
type
()
==
CV_8UC1
||
src
.
type
()
==
CV_8UC4
);
func
(
src
,
wholeSrc
,
ofs
.
y
,
ofs
.
x
,
dst
,
static_cast
<
float
>
(
1.0
/
fy
),
static_cast
<
float
>
(
1.0
/
fx
),
interpolation
,
StreamAccessor
::
getStream
(
stream
));
useNpp
=
useNpp
&&
(
interpolation
==
INTER_NEAREST
||
interpolation
==
INTER_LINEAR
);
if
(
useNpp
)
{
typedef
NppStatus
(
*
func_t
)(
const
Npp8u
*
pSrc
,
NppiSize
oSrcSize
,
int
nSrcStep
,
NppiRect
oSrcROI
,
Npp8u
*
pDst
,
int
nDstStep
,
NppiSize
dstROISize
,
double
xFactor
,
double
yFactor
,
int
eInterpolation
);
const
func_t
funcs
[
4
]
=
{
nppiResize_8u_C1R
,
0
,
0
,
nppiResize_8u_C4R
};
static
const
int
npp_inter
[]
=
{
NPPI_INTER_NN
,
NPPI_INTER_LINEAR
,
NPPI_INTER_CUBIC
,
0
,
NPPI_INTER_LANCZOS
};
NppiSize
srcsz
;
srcsz
.
width
=
wholeSize
.
width
;
srcsz
.
height
=
wholeSize
.
height
;
NppiRect
srcrect
;
srcrect
.
x
=
ofs
.
x
;
srcrect
.
y
=
ofs
.
y
;
srcrect
.
width
=
src
.
cols
;
srcrect
.
height
=
src
.
rows
;
NppiSize
dstsz
;
dstsz
.
width
=
dst
.
cols
;
dstsz
.
height
=
dst
.
rows
;
NppStreamHandler
h
(
stream
);
nppSafeCall
(
funcs
[
src
.
channels
()
-
1
](
src
.
datastart
,
srcsz
,
static_cast
<
int
>
(
src
.
step
),
srcrect
,
dst
.
ptr
<
Npp8u
>
(),
static_cast
<
int
>
(
dst
.
step
),
dstsz
,
fx
,
fy
,
npp_inter
[
interpolation
])
);
if
(
stream
==
0
)
cudaSafeCall
(
cudaDeviceSynchronize
()
);
}
else
{
using
namespace
::
cv
::
gpu
::
device
::
imgproc
;
typedef
void
(
*
func_t
)(
PtrStepSzb
src
,
PtrStepSzb
srcWhole
,
int
xoff
,
int
yoff
,
float
fx
,
float
fy
,
PtrStepSzb
dst
,
int
interpolation
,
cudaStream_t
stream
);
static
const
func_t
funcs
[
6
][
4
]
=
{
{
resize_gpu
<
uchar
>
,
0
/*resize_gpu<uchar2>*/
,
resize_gpu
<
uchar3
>
,
resize_gpu
<
uchar4
>
},
{
0
/*resize_gpu<schar>*/
,
0
/*resize_gpu<char2>*/
,
0
/*resize_gpu<char3>*/
,
0
/*resize_gpu<char4>*/
},
{
resize_gpu
<
ushort
>
,
0
/*resize_gpu<ushort2>*/
,
resize_gpu
<
ushort3
>
,
resize_gpu
<
ushort4
>
},
{
resize_gpu
<
short
>
,
0
/*resize_gpu<short2>*/
,
resize_gpu
<
short3
>
,
resize_gpu
<
short4
>
},
{
0
/*resize_gpu<int>*/
,
0
/*resize_gpu<int2>*/
,
0
/*resize_gpu<int3>*/
,
0
/*resize_gpu<int4>*/
},
{
resize_gpu
<
float
>
,
0
/*resize_gpu<float2>*/
,
resize_gpu
<
float3
>
,
resize_gpu
<
float4
>
}
};
const
func_t
func
=
funcs
[
src
.
depth
()][
src
.
channels
()
-
1
];
CV_Assert
(
func
!=
0
);
func
(
src
,
PtrStepSzb
(
wholeSize
.
height
,
wholeSize
.
width
,
src
.
datastart
,
src
.
step
),
ofs
.
x
,
ofs
.
y
,
static_cast
<
float
>
(
1.0
/
fx
),
static_cast
<
float
>
(
1.0
/
fy
),
dst
,
interpolation
,
stream
);
}
}
}
#endif // HAVE_CUDA
#endif // HAVE_CUDA
modules/gpu/test/test_resize.cpp
View file @
d44adcd6
...
@@ -155,7 +155,7 @@ GPU_TEST_P(Resize, Accuracy)
...
@@ -155,7 +155,7 @@ GPU_TEST_P(Resize, Accuracy)
INSTANTIATE_TEST_CASE_P
(
GPU_ImgProc
,
Resize
,
testing
::
Combine
(
INSTANTIATE_TEST_CASE_P
(
GPU_ImgProc
,
Resize
,
testing
::
Combine
(
ALL_DEVICES
,
ALL_DEVICES
,
DIFFERENT_SIZES
,
DIFFERENT_SIZES
,
testing
::
Values
(
MatType
(
CV_8UC
3
),
MatType
(
CV_16UC1
),
MatType
(
CV_16UC3
),
MatType
(
CV_16UC4
),
MatType
(
CV_32FC1
),
MatType
(
CV_32FC3
),
MatType
(
CV_32FC4
)),
testing
::
Values
(
MatType
(
CV_8UC
1
),
MatType
(
CV_8UC3
),
MatType
(
CV_8UC4
),
MatType
(
CV_16UC1
),
MatType
(
CV_16UC3
),
MatType
(
CV_16UC4
),
MatType
(
CV_32FC1
),
MatType
(
CV_32FC3
),
MatType
(
CV_32FC4
)),
testing
::
Values
(
0.3
,
0.5
,
1.5
,
2.0
),
testing
::
Values
(
0.3
,
0.5
,
1.5
,
2.0
),
testing
::
Values
(
Interpolation
(
cv
::
INTER_NEAREST
),
Interpolation
(
cv
::
INTER_LINEAR
),
Interpolation
(
cv
::
INTER_CUBIC
)),
testing
::
Values
(
Interpolation
(
cv
::
INTER_NEAREST
),
Interpolation
(
cv
::
INTER_LINEAR
),
Interpolation
(
cv
::
INTER_CUBIC
)),
WHOLE_SUBMAT
));
WHOLE_SUBMAT
));
...
@@ -201,50 +201,9 @@ GPU_TEST_P(ResizeSameAsHost, Accuracy)
...
@@ -201,50 +201,9 @@ GPU_TEST_P(ResizeSameAsHost, Accuracy)
INSTANTIATE_TEST_CASE_P
(
GPU_ImgProc
,
ResizeSameAsHost
,
testing
::
Combine
(
INSTANTIATE_TEST_CASE_P
(
GPU_ImgProc
,
ResizeSameAsHost
,
testing
::
Combine
(
ALL_DEVICES
,
ALL_DEVICES
,
DIFFERENT_SIZES
,
DIFFERENT_SIZES
,
testing
::
Values
(
MatType
(
CV_8UC
3
),
MatType
(
CV_16UC1
),
MatType
(
CV_16UC3
),
MatType
(
CV_16UC4
),
MatType
(
CV_32FC1
),
MatType
(
CV_32FC3
),
MatType
(
CV_32FC4
)),
testing
::
Values
(
MatType
(
CV_8UC
1
),
MatType
(
CV_8UC3
),
MatType
(
CV_8UC4
),
MatType
(
CV_16UC1
),
MatType
(
CV_16UC3
),
MatType
(
CV_16UC4
),
MatType
(
CV_32FC1
),
MatType
(
CV_32FC3
),
MatType
(
CV_32FC4
)),
testing
::
Values
(
0.3
,
0.5
),
testing
::
Values
(
0.3
,
0.5
),
testing
::
Values
(
Interpolation
(
cv
::
INTER_
AREA
),
Interpolation
(
cv
::
INTER_NEAREST
)),
//, Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)
testing
::
Values
(
Interpolation
(
cv
::
INTER_
NEAREST
),
Interpolation
(
cv
::
INTER_AREA
)),
WHOLE_SUBMAT
));
WHOLE_SUBMAT
));
///////////////////////////////////////////////////////////////////
// Test NPP
PARAM_TEST_CASE
(
ResizeNPP
,
cv
::
gpu
::
DeviceInfo
,
MatType
,
double
,
Interpolation
)
{
cv
::
gpu
::
DeviceInfo
devInfo
;
double
coeff
;
int
interpolation
;
int
type
;
virtual
void
SetUp
()
{
devInfo
=
GET_PARAM
(
0
);
type
=
GET_PARAM
(
1
);
coeff
=
GET_PARAM
(
2
);
interpolation
=
GET_PARAM
(
3
);
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
}
};
GPU_TEST_P
(
ResizeNPP
,
Accuracy
)
{
cv
::
Mat
src
=
readImageType
(
"stereobp/aloe-L.png"
,
type
);
ASSERT_FALSE
(
src
.
empty
());
cv
::
gpu
::
GpuMat
dst
;
cv
::
gpu
::
resize
(
loadMat
(
src
),
dst
,
cv
::
Size
(),
coeff
,
coeff
,
interpolation
);
cv
::
Mat
dst_gold
;
resizeGold
(
src
,
dst_gold
,
coeff
,
coeff
,
interpolation
);
EXPECT_MAT_SIMILAR
(
dst_gold
,
dst
,
1e-1
);
}
INSTANTIATE_TEST_CASE_P
(
GPU_ImgProc
,
ResizeNPP
,
testing
::
Combine
(
ALL_DEVICES
,
testing
::
Values
(
MatType
(
CV_8UC1
),
MatType
(
CV_8UC4
)),
testing
::
Values
(
0.3
,
0.5
,
1.5
,
2.0
),
testing
::
Values
(
Interpolation
(
cv
::
INTER_NEAREST
),
Interpolation
(
cv
::
INTER_LINEAR
))));
#endif // HAVE_CUDA
#endif // HAVE_CUDA
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment