Commit da3b7c79 authored by Ilya Lavrenov's avatar Ilya Lavrenov

refactored filters in the ocl module; added an accuracy tests for ocl::medianFilter

parent c5afaa4e
...@@ -666,3 +666,17 @@ Performs linear blending of two images. ...@@ -666,3 +666,17 @@ Performs linear blending of two images.
:param weights2: Weights for second image. Must have tha same size as ``img2`` . Supports only ``CV_32F`` type. :param weights2: Weights for second image. Must have tha same size as ``img2`` . Supports only ``CV_32F`` type.
:param result: Destination image. :param result: Destination image.
ocl::medianFilter
--------------------
Blurs an image using the median filter.
.. ocv:function:: void ocl::medianFilter(const oclMat &src, oclMat &dst, int m)
:param src: input ```1-``` or ```4```-channel image; the image depth should be ```CV_8U```, ```CV_32F```.
:param dst: destination array of the same size and type as ```src```.
:param m: aperture linear size; it must be odd and greater than ```1```. Currently only ```3```, ```5``` are supported.
The function smoothes an image using the median filter with the \texttt{m} \times \texttt{m} aperture. Each channel of a multi-channel image is processed independently. In-place operation is supported.
...@@ -839,11 +839,8 @@ namespace cv ...@@ -839,11 +839,8 @@ namespace cv
//! Applies a generic geometrical transformation to an image. //! Applies a generic geometrical transformation to an image.
// Supports INTER_NEAREST, INTER_LINEAR. // Supports INTER_NEAREST, INTER_LINEAR.
// Map1 supports CV_16SC2, CV_32FC2 types. // Map1 supports CV_16SC2, CV_32FC2 types.
// Src supports CV_8UC1, CV_8UC2, CV_8UC4. // Src supports CV_8UC1, CV_8UC2, CV_8UC4.
CV_EXPORTS void remap(const oclMat &src, oclMat &dst, oclMat &map1, oclMat &map2, int interpolation, int bordertype, const Scalar &value = Scalar()); CV_EXPORTS void remap(const oclMat &src, oclMat &dst, oclMat &map1, oclMat &map2, int interpolation, int bordertype, const Scalar &value = Scalar());
//! copies 2D array to a larger destination array and pads borders with user-specifiable constant //! copies 2D array to a larger destination array and pads borders with user-specifiable constant
...@@ -851,7 +848,7 @@ namespace cv ...@@ -851,7 +848,7 @@ namespace cv
CV_EXPORTS void copyMakeBorder(const oclMat &src, oclMat &dst, int top, int bottom, int left, int right, int boardtype, const Scalar &value = Scalar()); CV_EXPORTS void copyMakeBorder(const oclMat &src, oclMat &dst, int top, int bottom, int left, int right, int boardtype, const Scalar &value = Scalar());
//! Smoothes image using median filter //! Smoothes image using median filter
// The source 1- or 4-channel image. When m is 3 or 5, the image depth should be CV 8U or CV 32F. // The source 1- or 4-channel image. m should be 3 or 5, the image depth should be CV_8U or CV_32F.
CV_EXPORTS void medianFilter(const oclMat &src, oclMat &dst, int m); CV_EXPORTS void medianFilter(const oclMat &src, oclMat &dst, int m);
//! warps the image using affine transformation //! warps the image using affine transformation
......
...@@ -197,8 +197,8 @@ static void GPUErode(const oclMat &src, oclMat &dst, oclMat &mat_kernel, ...@@ -197,8 +197,8 @@ static void GPUErode(const oclMat &src, oclMat &dst, oclMat &mat_kernel,
(src.rows == dst.rows)); (src.rows == dst.rows));
CV_Assert((src.oclchannels() == dst.oclchannels())); CV_Assert((src.oclchannels() == dst.oclchannels()));
int srcStep = src.step1() / src.oclchannels(); int srcStep = src.step / src.elemSize();
int dstStep = dst.step1() / dst.oclchannels(); int dstStep = dst.step / dst.elemSize();
int srcOffset = src.offset / src.elemSize(); int srcOffset = src.offset / src.elemSize();
int dstOffset = dst.offset / dst.elemSize(); int dstOffset = dst.offset / dst.elemSize();
...@@ -247,6 +247,7 @@ static void GPUErode(const oclMat &src, oclMat &dst, oclMat &mat_kernel, ...@@ -247,6 +247,7 @@ static void GPUErode(const oclMat &src, oclMat &dst, oclMat &mat_kernel,
sprintf(compile_option, "-D RADIUSX=%d -D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D ERODE %s %s", sprintf(compile_option, "-D RADIUSX=%d -D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D ERODE %s %s",
anchor.x, anchor.y, (int)localThreads[0], (int)localThreads[1], anchor.x, anchor.y, (int)localThreads[0], (int)localThreads[1],
s, rectKernel?"-D RECTKERNEL":""); s, rectKernel?"-D RECTKERNEL":"");
vector< pair<size_t, const void *> > args; vector< pair<size_t, const void *> > args;
args.push_back(make_pair(sizeof(cl_mem), (void *)&src.data)); args.push_back(make_pair(sizeof(cl_mem), (void *)&src.data));
args.push_back(make_pair(sizeof(cl_mem), (void *)&dst.data)); args.push_back(make_pair(sizeof(cl_mem), (void *)&dst.data));
...@@ -260,6 +261,7 @@ static void GPUErode(const oclMat &src, oclMat &dst, oclMat &mat_kernel, ...@@ -260,6 +261,7 @@ static void GPUErode(const oclMat &src, oclMat &dst, oclMat &mat_kernel,
args.push_back(make_pair(sizeof(cl_int), (void *)&src.wholecols)); args.push_back(make_pair(sizeof(cl_int), (void *)&src.wholecols));
args.push_back(make_pair(sizeof(cl_int), (void *)&src.wholerows)); args.push_back(make_pair(sizeof(cl_int), (void *)&src.wholerows));
args.push_back(make_pair(sizeof(cl_int), (void *)&dstOffset)); args.push_back(make_pair(sizeof(cl_int), (void *)&dstOffset));
openCLExecuteKernel(clCxt, &filtering_morph, kernelName, globalThreads, localThreads, args, -1, -1, compile_option); openCLExecuteKernel(clCxt, &filtering_morph, kernelName, globalThreads, localThreads, args, -1, -1, compile_option);
} }
...@@ -351,7 +353,7 @@ Ptr<BaseFilter_GPU> cv::ocl::getMorphologyFilter_GPU(int op, int type, const Mat ...@@ -351,7 +353,7 @@ Ptr<BaseFilter_GPU> cv::ocl::getMorphologyFilter_GPU(int op, int type, const Mat
}; };
CV_Assert(op == MORPH_ERODE || op == MORPH_DILATE); CV_Assert(op == MORPH_ERODE || op == MORPH_DILATE);
CV_Assert(type == CV_8UC1 || type == CV_8UC3 || type == CV_8UC4 || type == CV_32FC1 || type == CV_32FC1 || type == CV_32FC4); CV_Assert(type == CV_8UC1 || type == CV_8UC3 || type == CV_8UC4 || type == CV_32FC1 || type == CV_32FC3 || type == CV_32FC4);
oclMat gpu_krnl; oclMat gpu_krnl;
normalizeKernel(kernel, gpu_krnl); normalizeKernel(kernel, gpu_krnl);
...@@ -361,9 +363,11 @@ Ptr<BaseFilter_GPU> cv::ocl::getMorphologyFilter_GPU(int op, int type, const Mat ...@@ -361,9 +363,11 @@ Ptr<BaseFilter_GPU> cv::ocl::getMorphologyFilter_GPU(int op, int type, const Mat
for(int i = 0; i < kernel.rows * kernel.cols; ++i) for(int i = 0; i < kernel.rows * kernel.cols; ++i)
if(kernel.data[i] != 1) if(kernel.data[i] != 1)
noZero = false; noZero = false;
MorphFilter_GPU* mfgpu=new MorphFilter_GPU(ksize, anchor, gpu_krnl, GPUMorfFilter_callers[op][CV_MAT_CN(type)]);
MorphFilter_GPU* mfgpu = new MorphFilter_GPU(ksize, anchor, gpu_krnl, GPUMorfFilter_callers[op][CV_MAT_CN(type)]);
if(noZero) if(noZero)
mfgpu->rectKernel = true; mfgpu->rectKernel = true;
return Ptr<BaseFilter_GPU>(mfgpu); return Ptr<BaseFilter_GPU>(mfgpu);
} }
...@@ -445,9 +449,7 @@ void morphOp(int op, const oclMat &src, oclMat &dst, const Mat &_kernel, Point a ...@@ -445,9 +449,7 @@ void morphOp(int op, const oclMat &src, oclMat &dst, const Mat &_kernel, Point a
iterations = 1; iterations = 1;
} }
else else
{
kernel = _kernel; kernel = _kernel;
}
Ptr<FilterEngine_GPU> f = createMorphologyFilter_GPU(op, src.type(), kernel, anchor, iterations); Ptr<FilterEngine_GPU> f = createMorphologyFilter_GPU(op, src.type(), kernel, anchor, iterations);
...@@ -462,14 +464,10 @@ void cv::ocl::erode(const oclMat &src, oclMat &dst, const Mat &kernel, Point anc ...@@ -462,14 +464,10 @@ void cv::ocl::erode(const oclMat &src, oclMat &dst, const Mat &kernel, Point anc
for (int i = 0; i < kernel.rows * kernel.cols; ++i) for (int i = 0; i < kernel.rows * kernel.cols; ++i)
if (kernel.data[i] != 0) if (kernel.data[i] != 0)
{
allZero = false; allZero = false;
}
if (allZero) if (allZero)
{
kernel.data[0] = 1; kernel.data[0] = 1;
}
morphOp(MORPH_ERODE, src, dst, kernel, anchor, iterations, borderType, borderValue); morphOp(MORPH_ERODE, src, dst, kernel, anchor, iterations, borderType, borderValue);
} }
...@@ -558,7 +556,7 @@ static void GPUFilter2D(const oclMat &src, oclMat &dst, const oclMat &mat_kernel ...@@ -558,7 +556,7 @@ static void GPUFilter2D(const oclMat &src, oclMat &dst, const oclMat &mat_kernel
Context *clCxt = src.clCxt; Context *clCxt = src.clCxt;
int filterWidth = ksize.width; int filterWidth = ksize.width;
bool ksize_3x3 = filterWidth == 3 && src.type() != CV_32FC4; // CV_32FC4 is not tuned up with filter2d_3x3 kernel bool ksize_3x3 = filterWidth == 3 && src.type() != CV_32FC4 && src.type() != CV_32FC3; // CV_32FC4 is not tuned up with filter2d_3x3 kernel
string kernelName = ksize_3x3 ? "filter2D_3x3" : "filter2D"; string kernelName = ksize_3x3 ? "filter2D_3x3" : "filter2D";
...@@ -649,9 +647,7 @@ Ptr<BaseFilter_GPU> cv::ocl::getLinearFilter_GPU(int srcType, int dstType, const ...@@ -649,9 +647,7 @@ Ptr<BaseFilter_GPU> cv::ocl::getLinearFilter_GPU(int srcType, int dstType, const
Ptr<FilterEngine_GPU> cv::ocl::createLinearFilter_GPU(int srcType, int dstType, const Mat &kernel, const Point &anchor, Ptr<FilterEngine_GPU> cv::ocl::createLinearFilter_GPU(int srcType, int dstType, const Mat &kernel, const Point &anchor,
int borderType) int borderType)
{ {
Size ksize = kernel.size(); Size ksize = kernel.size();
Ptr<BaseFilter_GPU> linearFilter = getLinearFilter_GPU(srcType, dstType, kernel, ksize, anchor, borderType); Ptr<BaseFilter_GPU> linearFilter = getLinearFilter_GPU(srcType, dstType, kernel, ksize, anchor, borderType);
return createFilter2D_GPU(linearFilter); return createFilter2D_GPU(linearFilter);
...@@ -659,11 +655,8 @@ Ptr<FilterEngine_GPU> cv::ocl::createLinearFilter_GPU(int srcType, int dstType, ...@@ -659,11 +655,8 @@ Ptr<FilterEngine_GPU> cv::ocl::createLinearFilter_GPU(int srcType, int dstType,
void cv::ocl::filter2D(const oclMat &src, oclMat &dst, int ddepth, const Mat &kernel, Point anchor, int borderType) void cv::ocl::filter2D(const oclMat &src, oclMat &dst, int ddepth, const Mat &kernel, Point anchor, int borderType)
{ {
if (ddepth < 0) if (ddepth < 0)
{
ddepth = src.depth(); ddepth = src.depth();
}
dst.create(src.size(), CV_MAKETYPE(ddepth, src.channels())); dst.create(src.size(), CV_MAKETYPE(ddepth, src.channels()));
...@@ -1444,9 +1437,7 @@ Ptr<FilterEngine_GPU> cv::ocl::createGaussianFilter_GPU(int type, Size ksize, do ...@@ -1444,9 +1437,7 @@ Ptr<FilterEngine_GPU> cv::ocl::createGaussianFilter_GPU(int type, Size ksize, do
int depth = CV_MAT_DEPTH(type); int depth = CV_MAT_DEPTH(type);
if (sigma2 <= 0) if (sigma2 <= 0)
{
sigma2 = sigma1; sigma2 = sigma1;
}
// automatic detection of kernel size from sigma // automatic detection of kernel size from sigma
if (ksize.width <= 0 && sigma1 > 0) if (ksize.width <= 0 && sigma1 > 0)
......
...@@ -408,20 +408,11 @@ namespace cv ...@@ -408,20 +408,11 @@ namespace cv
void medianFilter(const oclMat &src, oclMat &dst, int m) void medianFilter(const oclMat &src, oclMat &dst, int m)
{ {
CV_Assert( m % 2 == 1 && m > 1 ); CV_Assert( m % 2 == 1 && m > 1 );
CV_Assert( m <= 5 || src.depth() == CV_8U ); CV_Assert( (src.depth() == CV_8U || src.depth() == CV_32F) && (src.channels() == 1 || src.channels() == 4));
CV_Assert( src.cols <= dst.cols && src.rows <= dst.rows ); dst.create(src.size(), src.type());
if (src.data == dst.data)
{
oclMat src1;
src.copyTo(src1);
return medianFilter(src1, dst, m);
}
int srcStep = src.step1() / src.oclchannels(); int srcStep = src.step / src.elemSize(), dstStep = dst.step / dst.elemSize();
int dstStep = dst.step1() / dst.oclchannels(); int srcOffset = src.offset / src.elemSize(), dstOffset = dst.offset / dst.elemSize();
int srcOffset = src.offset / src.oclchannels() / src.elemSize1();
int dstOffset = dst.offset / dst.oclchannels() / dst.elemSize1();
Context *clCxt = src.clCxt; Context *clCxt = src.clCxt;
...@@ -1518,6 +1509,7 @@ namespace cv ...@@ -1518,6 +1509,7 @@ namespace cv
float *color_weight = &_color_weight[0]; float *color_weight = &_color_weight[0];
float *space_weight = &_space_weight[0]; float *space_weight = &_space_weight[0];
int *space_ofs = &_space_ofs[0]; int *space_ofs = &_space_ofs[0];
int dst_step_in_pixel = dst.step / dst.elemSize(); int dst_step_in_pixel = dst.step / dst.elemSize();
int dst_offset_in_pixel = dst.offset / dst.elemSize(); int dst_offset_in_pixel = dst.offset / dst.elemSize();
int temp_step_in_pixel = temp.step / temp.elemSize(); int temp_step_in_pixel = temp.step / temp.elemSize();
...@@ -1548,7 +1540,7 @@ namespace cv ...@@ -1548,7 +1540,7 @@ namespace cv
if ((dst.type() == CV_8UC1) && ((dst.offset & 3) == 0) && ((dst.cols & 3) == 0)) if ((dst.type() == CV_8UC1) && ((dst.offset & 3) == 0) && ((dst.cols & 3) == 0))
{ {
kernelName = "bilateral2"; kernelName = "bilateral2";
globalThreads[0] = dst.cols / 4; globalThreads[0] = dst.cols >> 2;
} }
vector<pair<size_t , const void *> > args; vector<pair<size_t , const void *> > args;
...@@ -1566,15 +1558,17 @@ namespace cv ...@@ -1566,15 +1558,17 @@ namespace cv
args.push_back( make_pair( sizeof(cl_mem), (void *)&oclcolor_weight.data )); args.push_back( make_pair( sizeof(cl_mem), (void *)&oclcolor_weight.data ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&oclspace_weight.data )); args.push_back( make_pair( sizeof(cl_mem), (void *)&oclspace_weight.data ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&oclspace_ofs.data )); args.push_back( make_pair( sizeof(cl_mem), (void *)&oclspace_ofs.data ));
openCLExecuteKernel(src.clCxt, &imgproc_bilateral, kernelName, globalThreads, localThreads, args, dst.oclchannels(), dst.depth()); openCLExecuteKernel(src.clCxt, &imgproc_bilateral, kernelName, globalThreads, localThreads, args, dst.oclchannels(), dst.depth());
} }
void bilateralFilter(const oclMat &src, oclMat &dst, int radius, double sigmaclr, double sigmaspc, int borderType) void bilateralFilter(const oclMat &src, oclMat &dst, int radius, double sigmaclr, double sigmaspc, int borderType)
{ {
dst.create( src.size(), src.type() ); dst.create( src.size(), src.type() );
if ( src.depth() == CV_8U ) if ( src.depth() == CV_8U )
oclbilateralFilter_8u( src, dst, radius, sigmaclr, sigmaspc, borderType ); oclbilateralFilter_8u( src, dst, radius, sigmaclr, sigmaspc, borderType );
else else
CV_Error( CV_StsUnsupportedFormat, "Bilateral filtering is only implemented for 8uimages" ); CV_Error( CV_StsUnsupportedFormat, "Bilateral filtering is only implemented for CV_8U images" );
} }
} }
......
...@@ -169,6 +169,7 @@ __kernel void filter2D( ...@@ -169,6 +169,7 @@ __kernel void filter2D(
int globalRow = groupStartRow + localRow; int globalRow = groupStartRow + localRow;
const int src_offset = mad24(src_offset_y, src_step, src_offset_x); const int src_offset = mad24(src_offset_y, src_step, src_offset_x);
const int dst_offset = mad24(dst_offset_y, dst_step, dst_offset_x); const int dst_offset = mad24(dst_offset_y, dst_step, dst_offset_x);
#ifdef BORDER_CONSTANT #ifdef BORDER_CONSTANT
for(int i = localRow; i < LOCAL_HEIGHT; i += get_local_size(1)) for(int i = localRow; i < LOCAL_HEIGHT; i += get_local_size(1))
{ {
...@@ -208,6 +209,7 @@ __kernel void filter2D( ...@@ -208,6 +209,7 @@ __kernel void filter2D(
} }
} }
#endif #endif
barrier(CLK_LOCAL_MEM_FENCE); barrier(CLK_LOCAL_MEM_FENCE);
if(globalRow < rows && globalCol < cols) if(globalRow < rows && globalCol < cols)
{ {
...@@ -231,6 +233,7 @@ __kernel void filter2D( ...@@ -231,6 +233,7 @@ __kernel void filter2D(
////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////Macro for define elements number per thread///////////////////////////// /////////////////////////////Macro for define elements number per thread/////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
#define ANX 1 #define ANX 1
#define ANY 1 #define ANY 1
...@@ -249,6 +252,7 @@ __kernel void filter2D( ...@@ -249,6 +252,7 @@ __kernel void filter2D(
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////8uC1//////////////////////////////////////////////////////// /////////////////////////////////////////8uC1////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
__kernel void filter2D_3x3( __kernel void filter2D_3x3(
__global T_IMG *src, __global T_IMG *src,
__global T_IMG *dst, __global T_IMG *dst,
...@@ -359,6 +363,7 @@ __kernel void filter2D_3x3( ...@@ -359,6 +363,7 @@ __kernel void filter2D_3x3(
} }
} }
} }
if(dst_rows_index < dst_rows_end) if(dst_rows_index < dst_rows_end)
{ {
T_IMGx4 tmp_dst = CONVERT_TYPEx4(sum); T_IMGx4 tmp_dst = CONVERT_TYPEx4(sum);
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
//BORDER_CONSTANT: iiiiii|abcdefgh|iiiiiii //BORDER_CONSTANT: iiiiii|abcdefgh|iiiiiii
#define ELEM(i,l_edge,r_edge,elem1,elem2) (i)<(l_edge) | (i) >= (r_edge) ? (elem1) : (elem2) #define ELEM(i,l_edge,r_edge,elem1,elem2) (i)<(l_edge) | (i) >= (r_edge) ? (elem1) : (elem2)
#ifndef GENTYPE #ifndef GENTYPE
__kernel void morph_C1_D0(__global const uchar * restrict src, __kernel void morph_C1_D0(__global const uchar * restrict src,
__global uchar *dst, __global uchar *dst,
int src_offset_x, int src_offset_y, int src_offset_x, int src_offset_y,
...@@ -150,7 +151,9 @@ __kernel void morph_C1_D0(__global const uchar * restrict src, ...@@ -150,7 +151,9 @@ __kernel void morph_C1_D0(__global const uchar * restrict src,
} }
} }
} }
#else #else
__kernel void morph(__global const GENTYPE * restrict src, __kernel void morph(__global const GENTYPE * restrict src,
__global GENTYPE *dst, __global GENTYPE *dst,
int src_offset_x, int src_offset_y, int src_offset_x, int src_offset_y,
...@@ -221,4 +224,5 @@ __kernel void morph(__global const GENTYPE * restrict src, ...@@ -221,4 +224,5 @@ __kernel void morph(__global const GENTYPE * restrict src,
dst[out_addr] = res; dst[out_addr] = res;
} }
} }
#endif #endif
...@@ -47,25 +47,27 @@ __kernel void bilateral_C1_D0(__global uchar *dst, ...@@ -47,25 +47,27 @@ __kernel void bilateral_C1_D0(__global uchar *dst,
__constant float *space_weight, __constant float *space_weight,
__constant int *space_ofs) __constant int *space_ofs)
{ {
int gidx = get_global_id(0); int x = get_global_id(0);
int gidy = get_global_id(1); int y = get_global_id(1);
if((gidy<dst_rows) && (gidx<dst_cols))
if (y < dst_rows && x < dst_cols)
{ {
int src_addr = mad24(gidy+radius,src_step,gidx+radius); int src_index = mad24(y + radius, src_step, x + radius);
int dst_addr = mad24(gidy,dst_step,gidx+dst_offset); int dst_index = mad24(y, dst_step, x + dst_offset);
float sum = 0.f, wsum = 0.f; float sum = 0.f, wsum = 0.f;
int val0 = (int)src[src_addr]; int val0 = (int)src[src_index];
for(int k = 0; k < maxk; k++ ) for(int k = 0; k < maxk; k++ )
{ {
int val = (int)src[src_addr + space_ofs[k]]; int val = (int)src[src_index + space_ofs[k]];
float w = space_weight[k]*color_weight[abs(val - val0)]; float w = space_weight[k] * color_weight[abs(val - val0)];
sum += (float)(val)*w; sum += (float)(val) * w;
wsum += w; wsum += w;
} }
dst[dst_addr] = convert_uchar_rtz(sum/wsum+0.5f); dst[dst_index] = convert_uchar_rtz(sum / wsum + 0.5f);
} }
} }
__kernel void bilateral2_C1_D0(__global uchar *dst, __kernel void bilateral2_C1_D0(__global uchar *dst,
__global const uchar *src, __global const uchar *src,
const int dst_rows, const int dst_rows,
...@@ -81,25 +83,28 @@ __kernel void bilateral2_C1_D0(__global uchar *dst, ...@@ -81,25 +83,28 @@ __kernel void bilateral2_C1_D0(__global uchar *dst,
__constant float *space_weight, __constant float *space_weight,
__constant int *space_ofs) __constant int *space_ofs)
{ {
int gidx = get_global_id(0)<<2; int x = get_global_id(0) << 2;
int gidy = get_global_id(1); int y = get_global_id(1);
if((gidy<dst_rows) && (gidx<dst_cols))
if (y < dst_rows && x < dst_cols)
{ {
int src_addr = mad24(gidy+radius,src_step,gidx+radius); int src_index = mad24(y + radius, src_step, x + radius);
int dst_addr = mad24(gidy,dst_step,gidx+dst_offset); int dst_index = mad24(y, dst_step, x + dst_offset);
float4 sum = (float4)(0.f), wsum = (float4)(0.f); float4 sum = (float4)(0.f), wsum = (float4)(0.f);
int4 val0 = convert_int4(vload4(0,src+src_addr)); int4 val0 = convert_int4(vload4(0,src + src_index));
for(int k = 0; k < maxk; k++ ) for(int k = 0; k < maxk; k++ )
{ {
int4 val = convert_int4(vload4(0,src+src_addr + space_ofs[k])); int4 val = convert_int4(vload4(0,src+src_index + space_ofs[k]));
float4 w = (float4)(space_weight[k])*(float4)(color_weight[abs(val.x - val0.x)],color_weight[abs(val.y - val0.y)],color_weight[abs(val.z - val0.z)],color_weight[abs(val.w - val0.w)]); float4 w = (float4)(space_weight[k]) * (float4)(color_weight[abs(val.x - val0.x)], color_weight[abs(val.y - val0.y)],
sum += convert_float4(val)*w; color_weight[abs(val.z - val0.z)], color_weight[abs(val.w - val0.w)]);
sum += convert_float4(val) * w;
wsum += w; wsum += w;
} }
*(__global uchar4*)(dst+dst_addr) = convert_uchar4_rtz(sum/wsum+0.5f); *(__global uchar4*)(dst+dst_index) = convert_uchar4_rtz(sum/wsum+0.5f);
} }
} }
__kernel void bilateral_C4_D0(__global uchar4 *dst, __kernel void bilateral_C4_D0(__global uchar4 *dst,
__global const uchar4 *src, __global const uchar4 *src,
const int dst_rows, const int dst_rows,
...@@ -115,24 +120,26 @@ __kernel void bilateral_C4_D0(__global uchar4 *dst, ...@@ -115,24 +120,26 @@ __kernel void bilateral_C4_D0(__global uchar4 *dst,
__constant float *space_weight, __constant float *space_weight,
__constant int *space_ofs) __constant int *space_ofs)
{ {
int gidx = get_global_id(0); int x = get_global_id(0);
int gidy = get_global_id(1); int y = get_global_id(1);
if((gidy<dst_rows) && (gidx<dst_cols))
if (y < dst_rows && x < dst_cols)
{ {
int src_addr = mad24(gidy+radius,src_step,gidx+radius); int src_index = mad24(y + radius, src_step, x + radius);
int dst_addr = mad24(gidy,dst_step,gidx+dst_offset); int dst_index = mad24(y, dst_step, x + dst_offset);
float4 sum = (float4)0.f; float4 sum = (float4)0.f;
float wsum = 0.f; float wsum = 0.f;
int4 val0 = convert_int4(src[src_addr]); int4 val0 = convert_int4(src[src_index]);
for(int k = 0; k < maxk; k++ ) for(int k = 0; k < maxk; k++ )
{ {
int4 val = convert_int4(src[src_addr + space_ofs[k]]); int4 val = convert_int4(src[src_index + space_ofs[k]]);
float w = space_weight[k]*color_weight[abs(val.x - val0.x)+abs(val.y - val0.y)+abs(val.z - val0.z)]; float w = space_weight[k] * color_weight[abs(val.x - val0.x) + abs(val.y - val0.y) + abs(val.z - val0.z)];
sum += convert_float4(val)*(float4)w; sum += convert_float4(val) * (float4)w;
wsum += w; wsum += w;
} }
wsum=1.f/wsum;
dst[dst_addr] = convert_uchar4_rtz(sum*(float4)wsum+(float4)0.5f); wsum = 1.f / wsum;
dst[dst_index] = convert_uchar4_rtz(sum * (float4)wsum + (float4)0.5f);
} }
} }
...@@ -52,424 +52,394 @@ ...@@ -52,424 +52,394 @@
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
using namespace cvtest;
using namespace testing; using namespace testing;
using namespace std; using namespace std;
using namespace cv;
PARAM_TEST_CASE(FilterTestBase, MatType,
PARAM_TEST_CASE(FilterTestBase, int, // kernel size
MatType, Size, // dx, dy
cv::Size, // kernel size int, // border type, or iteration
cv::Size, // dx,dy bool) // roi or not
int // border type, or iteration
)
{ {
//src mat int type, borderType;
cv::Mat mat1; int ksize;
cv::Mat dst; bool useRoi;
// set up roi
int roicols;
int roirows;
int src1x;
int src1y;
int dstx;
int dsty;
//src mat with roi
cv::Mat mat1_roi;
cv::Mat dst_roi;
//ocl dst mat for testing
cv::ocl::oclMat gdst_whole;
//ocl mat with roi Mat src, dst_whole, src_roi, dst_roi;
cv::ocl::oclMat gmat1; ocl::oclMat gsrc_whole, gsrc_roi, gdst_whole, gdst_roi;
cv::ocl::oclMat gdst;
void random_roi() virtual void SetUp()
{ {
#ifdef RANDOMROI type = GET_PARAM(0);
//randomize ROI ksize = GET_PARAM(1);
roicols = rng.uniform(2, mat1.cols); borderType = GET_PARAM(3);
roirows = rng.uniform(2, mat1.rows); useRoi = GET_PARAM(4);
src1x = rng.uniform(0, mat1.cols - roicols);
src1y = rng.uniform(0, mat1.rows - roirows);
dstx = rng.uniform(0, dst.cols - roicols);
dsty = rng.uniform(0, dst.rows - roirows);
#else
roicols = mat1.cols;
roirows = mat1.rows;
src1x = 0;
src1y = 0;
dstx = 0;
dsty = 0;
#endif
mat1_roi = mat1(Rect(src1x, src1y, roicols, roirows));
dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
gdst_whole = dst;
gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
gmat1 = mat1_roi;
} }
void Init(int mat_type) void random_roi()
{ {
cv::Size size(MWIDTH, MHEIGHT); Size roiSize = randomSize(1, MAX_VALUE);
mat1 = randomMat(size, mat_type, 5, 16); Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
dst = randomMat(size, mat_type, 5, 16); randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
randomSubMat(dst_whole, dst_roi, roiSize, dstBorder, type, 5, 16);
generateOclMat(gsrc_whole, gsrc_roi, src, roiSize, srcBorder);
generateOclMat(gdst_whole, gdst_roi, dst_whole, roiSize, dstBorder);
} }
void Near(double threshold) void Near(double threshold = 0.0)
{ {
EXPECT_MAT_NEAR(dst, Mat(gdst_whole), threshold); EXPECT_MAT_NEAR(dst_whole, Mat(gdst_whole), threshold);
EXPECT_MAT_NEAR(dst_roi, Mat(gdst_roi), threshold);
} }
}; };
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// blur // blur
struct Blur : FilterTestBase
{
int type;
cv::Size ksize;
int bordertype;
virtual void SetUp() typedef FilterTestBase Blur;
{
type = GET_PARAM(0);
ksize = GET_PARAM(1);
bordertype = GET_PARAM(3);
Init(type);
}
};
OCL_TEST_P(Blur, Mat) OCL_TEST_P(Blur, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) Size kernelSize(ksize, ksize);
for (int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::blur(mat1_roi, dst_roi, ksize, Point(-1, -1), bordertype);
cv::ocl::blur(gmat1, gdst, ksize, Point(-1, -1), bordertype); blur(src_roi, dst_roi, kernelSize, Point(-1, -1), borderType);
ocl::blur(gsrc_roi, gdst_roi, kernelSize, Point(-1, -1), borderType); // TODO anchor
Near(1.0); Near(1.0);
} }
} }
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
//Laplacian // Laplacian
struct Laplacian : FilterTestBase
{
int type;
cv::Size ksize;
virtual void SetUp() typedef FilterTestBase LaplacianTest;
{
type = GET_PARAM(0);
ksize = GET_PARAM(1);
Init(type);
}
};
OCL_TEST_P(Laplacian, Accuracy) OCL_TEST_P(LaplacianTest, Accuracy)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for (int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::Laplacian(mat1_roi, dst_roi, -1, ksize.width, 1);
cv::ocl::Laplacian(gmat1, gdst, -1, ksize.width, 1); Laplacian(src_roi, dst_roi, -1, ksize, 1);
ocl::Laplacian(gsrc_roi, gdst_roi, -1, ksize, 1); // TODO scale
Near(1e-5); Near(1e-5);
} }
} }
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// erode & dilate // erode & dilate
struct ErodeDilate : FilterTestBase
struct ErodeDilate :
public FilterTestBase
{ {
int type;
int iterations; int iterations;
//erode or dilate kernel
cv::Mat kernel;
virtual void SetUp() virtual void SetUp()
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
iterations = GET_PARAM(3); iterations = GET_PARAM(3);
Init(type); useRoi = GET_PARAM(4);
kernel = randomMat(Size(3, 3), CV_8UC1, 0, 3);
} }
}; };
OCL_TEST_P(ErodeDilate, Mat) typedef ErodeDilate Erode;
OCL_TEST_P(Erode, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) // erode or dilate kernel
Size kernelSize(ksize, ksize);
Mat kernel;
for (int j = 0; j < LOOP_TIMES; j++)
{ {
kernel = randomMat(kernelSize, CV_8UC1, 0, 3);
random_roi(); random_roi();
cv::erode(mat1_roi, dst_roi, kernel, Point(-1, -1), iterations);
cv::ocl::erode(gmat1, gdst, kernel, Point(-1, -1), iterations); cv::erode(src_roi, dst_roi, kernel, Point(-1, -1), iterations);
ocl::erode(gsrc_roi, gdst_roi, kernel, Point(-1, -1), iterations); // TODO iterations, borderType
Near(1e-5); Near(1e-5);
} }
for(int j = 0; j < LOOP_TIMES; j++) }
typedef ErodeDilate Dilate;
OCL_TEST_P(Dilate, Mat)
{
// erode or dilate kernel
Mat kernel;
for (int j = 0; j < LOOP_TIMES; j++)
{ {
kernel = randomMat(Size(3, 3), CV_8UC1, 0, 3);
random_roi(); random_roi();
cv::dilate(mat1_roi, dst_roi, kernel, Point(-1, -1), iterations);
cv::ocl::dilate(gmat1, gdst, kernel, Point(-1, -1), iterations); cv::dilate(src_roi, dst_roi, kernel, Point(-1, -1), iterations);
ocl::dilate(gsrc_roi, gdst_roi, kernel, Point(-1, -1), iterations); // TODO iterations, borderType
Near(1e-5); Near(1e-5);
} }
} }
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// Sobel // Sobel
struct Sobel : FilterTestBase
struct SobelTest :
public FilterTestBase
{ {
int type; int dx, dy;
int dx, dy, ksize, bordertype;
virtual void SetUp() virtual void SetUp()
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
Size s = GET_PARAM(1); ksize = GET_PARAM(1);
ksize = s.width; borderType = GET_PARAM(3);
s = GET_PARAM(2); useRoi = GET_PARAM(4);
dx = s.width;
dy = s.height; Size d = GET_PARAM(2);
bordertype = GET_PARAM(3); dx = d.width, dy = d.height;
Init(type);
} }
}; };
OCL_TEST_P(Sobel, Mat) OCL_TEST_P(SobelTest, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for (int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::Sobel(mat1_roi, dst_roi, -1, dx, dy, ksize, /*scale*/0.00001,/*delta*/0, bordertype);
cv::ocl::Sobel(gmat1, gdst, -1, dx, dy, ksize,/*scale*/0.00001,/*delta*/0, bordertype); Sobel(src_roi, dst_roi, -1, dx, dy, ksize, /* scale */ 0.00001, /* delta */0, borderType);
ocl::Sobel(gsrc_roi, gdst_roi, -1, dx, dy, ksize, /* scale */ 0.00001, /* delta */ 0, borderType);
Near(1); Near(1);
} }
} }
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// Scharr // Scharr
struct Scharr : FilterTestBase
{
int type;
int dx, dy, bordertype;
virtual void SetUp() typedef SobelTest ScharrTest;
{
type = GET_PARAM(0);
Size s = GET_PARAM(2);
dx = s.width;
dy = s.height;
bordertype = GET_PARAM(3);
Init(type);
}
};
OCL_TEST_P(Scharr, Mat) OCL_TEST_P(ScharrTest, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for (int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::Scharr(mat1_roi, dst_roi, -1, dx, dy, /*scale*/1,/*delta*/0, bordertype);
cv::ocl::Scharr(gmat1, gdst, -1, dx, dy,/*scale*/1,/*delta*/0, bordertype); Scharr(src_roi, dst_roi, -1, dx, dy, /* scale */ 1, /* delta */ 0, borderType);
ocl::Scharr(gsrc_roi, gdst_roi, -1, dx, dy, /* scale */ 1, /* delta */ 0, borderType);
Near(1); Near(1);
} }
} }
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// GaussianBlur // GaussianBlur
struct GaussianBlur : FilterTestBase
struct GaussianBlurTest :
public FilterTestBase
{ {
int type;
cv::Size ksize;
int bordertype;
double sigma1, sigma2; double sigma1, sigma2;
virtual void SetUp() virtual void SetUp()
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
ksize = GET_PARAM(1); ksize = GET_PARAM(1);
bordertype = GET_PARAM(3); borderType = GET_PARAM(3);
Init(type);
sigma1 = rng.uniform(0.1, 1.0); sigma1 = rng.uniform(0.1, 1.0);
sigma2 = rng.uniform(0.1, 1.0); sigma2 = rng.uniform(0.1, 1.0);
} }
}; };
OCL_TEST_P(GaussianBlur, Mat) OCL_TEST_P(GaussianBlurTest, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for (int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::GaussianBlur(mat1_roi, dst_roi, ksize, sigma1, sigma2, bordertype);
cv::ocl::GaussianBlur(gmat1, gdst, ksize, sigma1, sigma2, bordertype); GaussianBlur(src_roi, dst_roi, Size(ksize, ksize), sigma1, sigma2, borderType);
ocl::GaussianBlur(gsrc_roi, gdst_roi, Size(ksize, ksize), sigma1, sigma2, borderType);
Near(1); Near(1);
} }
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Filter2D // Filter2D
struct Filter2D : FilterTestBase
{ typedef FilterTestBase Filter2D;
int type;
cv::Size ksize;
int bordertype;
Point anchor;
virtual void SetUp()
{
type = GET_PARAM(0);
ksize = GET_PARAM(1);
bordertype = GET_PARAM(3);
Init(type);
anchor = Point(-1,-1);
}
};
OCL_TEST_P(Filter2D, Mat) OCL_TEST_P(Filter2D, Mat)
{ {
cv::Mat kernel = randomMat(cv::Size(ksize.width, ksize.height), CV_32FC1, 0.0, 1.0); const Size kernelSize(ksize, ksize);
for(int j = 0; j < LOOP_TIMES; j++) Mat kernel;
for (int j = 0; j < LOOP_TIMES; j++)
{ {
kernel = randomMat(kernelSize, CV_32FC1, 0.0, 1.0);
random_roi(); random_roi();
cv::filter2D(mat1_roi, dst_roi, -1, kernel, anchor, 0.0, bordertype);
cv::ocl::filter2D(gmat1, gdst, -1, kernel, anchor, bordertype); cv::filter2D(src_roi, dst_roi, -1, kernel, Point(-1, -1), 0.0, borderType); // TODO anchor
ocl::filter2D(gsrc_roi, gdst_roi, -1, kernel, Point(-1, -1), borderType);
Near(1); Near(1);
} }
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Bilateral // Bilateral
struct Bilateral : FilterTestBase
{
int type;
cv::Size ksize;
int bordertype;
double sigmacolor, sigmaspace;
virtual void SetUp() typedef FilterTestBase Bilateral;
{
type = GET_PARAM(0);
ksize = GET_PARAM(1);
bordertype = GET_PARAM(3);
Init(type);
sigmacolor = rng.uniform(20, 100);
sigmaspace = rng.uniform(10, 40);
}
};
OCL_TEST_P(Bilateral, Mat) OCL_TEST_P(Bilateral, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for (int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::bilateralFilter(mat1_roi, dst_roi, ksize.width, sigmacolor, sigmaspace, bordertype);
cv::ocl::bilateralFilter(gmat1, gdst, ksize.width, sigmacolor, sigmaspace, bordertype); double sigmacolor = rng.uniform(20, 100);
double sigmaspace = rng.uniform(10, 40);
cv::bilateralFilter(src_roi, dst_roi, ksize, sigmacolor, sigmaspace, borderType);
ocl::bilateralFilter(gsrc_roi, gdst_roi, ksize, sigmacolor, sigmaspace, borderType);
Near(1); Near(1);
} }
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// AdaptiveBilateral // AdaptiveBilateral
struct AdaptiveBilateral : FilterTestBase
{ typedef FilterTestBase AdaptiveBilateral;
int type;
cv::Size ksize;
int bordertype;
Point anchor;
virtual void SetUp()
{
type = GET_PARAM(0);
ksize = GET_PARAM(1);
bordertype = GET_PARAM(3);
Init(type);
anchor = Point(-1,-1);
}
};
OCL_TEST_P(AdaptiveBilateral, Mat) OCL_TEST_P(AdaptiveBilateral, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) const Size kernelSize(ksize, ksize);
for (int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::adaptiveBilateralFilter(mat1_roi, dst_roi, ksize, 5, anchor, bordertype);
cv::ocl::adaptiveBilateralFilter(gmat1, gdst, ksize, 5, anchor, bordertype); adaptiveBilateralFilter(src_roi, dst_roi, kernelSize, 5, Point(-1, -1), borderType); // TODO anchor
ocl::adaptiveBilateralFilter(gsrc_roi, gdst_roi, kernelSize, 5, Point(-1, -1), borderType);
Near(1); Near(1);
} }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
// MedianFilter
typedef FilterTestBase MedianFilter;
OCL_TEST_P(MedianFilter, Mat)
{
for (int i = 0; i < LOOP_TIMES; ++i)
{
random_roi();
medianBlur(src_roi, dst_roi, ksize);
ocl::medianFilter(gsrc_roi, gdst_roi, ksize);
Near();
}
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
INSTANTIATE_TEST_CASE_P(Filter, Blur, Combine( INSTANTIATE_TEST_CASE_P(Filter, Blur, Combine(
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4), Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
Values(cv::Size(3, 3), cv::Size(5, 5), cv::Size(7, 7)), Values(3, 5, 7),
Values(Size(0, 0)), //not use Values(Size(0, 0)), // not used
Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE, (MatType)cv::BORDER_REFLECT, (MatType)cv::BORDER_REFLECT_101))); Values((int)BORDER_CONSTANT, (int)BORDER_REPLICATE, (int)BORDER_REFLECT, (int)BORDER_REFLECT_101),
Bool()));
INSTANTIATE_TEST_CASE_P(Filter, LaplacianTest, Combine(
INSTANTIATE_TEST_CASE_P(Filter, Laplacian, Combine(
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
Values(Size(3, 3)), Values(1, 3),
Values(Size(0, 0)), //not use Values(Size(0, 0)), // not used
Values(0))); //not use Values(0), // not used
Bool()));
INSTANTIATE_TEST_CASE_P(Filter, ErodeDilate, Combine( INSTANTIATE_TEST_CASE_P(Filter, Erode, Combine(
Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
Values(Size(0, 0)), //not use Values(3, 5, 7),
Values(Size(0, 0)), //not use Values(Size(0, 0)), // not used
Values(1))); testing::Range(1, 2),
Bool()));
INSTANTIATE_TEST_CASE_P(Filter, Dilate, Combine(
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
Values(3, 5, 7),
Values(Size(0, 0)), // not used
testing::Range(1, 2),
Bool()));
INSTANTIATE_TEST_CASE_P(Filter, Sobel, Combine( INSTANTIATE_TEST_CASE_P(Filter, SobelTest, Combine(
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
Values(Size(3, 3), Size(5, 5)), Values(3, 5),
Values(Size(1, 0), Size(1, 1), Size(2, 0), Size(2, 1)), Values(Size(1, 0), Size(1, 1), Size(2, 0), Size(2, 1)),
Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE))); Values((int)BORDER_CONSTANT, (int)BORDER_REFLECT101,
(int)BORDER_REPLICATE, (int)BORDER_REFLECT),
Bool()));
INSTANTIATE_TEST_CASE_P(Filter, Scharr, Combine( INSTANTIATE_TEST_CASE_P(Filter, ScharrTest, Combine(
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4), Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
Values(Size(0, 0)), //not use Values(0), // not used
Values(Size(0, 1), Size(1, 0)), Values(Size(0, 1), Size(1, 0)),
Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE))); Values((int)BORDER_CONSTANT, (int)BORDER_REFLECT101,
(int)BORDER_REPLICATE, (int)BORDER_REFLECT),
Bool()));
INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur, Combine( INSTANTIATE_TEST_CASE_P(Filter, GaussianBlurTest, Combine(
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4), Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
Values(Size(3, 3), Size(5, 5)), Values(3, 5),
Values(Size(0, 0)), //not use Values(Size(0, 0)), // not used
Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE))); Values((int)BORDER_CONSTANT, (int)BORDER_REFLECT101,
(int)BORDER_REPLICATE, (int)BORDER_REFLECT),
Bool()));
INSTANTIATE_TEST_CASE_P(Filter, Filter2D, testing::Combine( INSTANTIATE_TEST_CASE_P(Filter, Filter2D, testing::Combine(
Values(CV_8UC1, CV_32FC1, CV_32FC4), Values(CV_8UC1, CV_32FC1, CV_32FC4),
Values(Size(3, 3), Size(15, 15), Size(25, 25)), Values(3, 15, 25),
Values(Size(0, 0)), //not use Values(Size(0, 0)), // not used
Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REFLECT101, (MatType)cv::BORDER_REPLICATE, (MatType)cv::BORDER_REFLECT))); Values((int)BORDER_CONSTANT, (int)BORDER_REFLECT101,
(int)BORDER_REPLICATE, (int)BORDER_REFLECT),
Bool()));
INSTANTIATE_TEST_CASE_P(Filter, Bilateral, Combine( INSTANTIATE_TEST_CASE_P(Filter, Bilateral, Combine(
Values(CV_8UC1, CV_8UC3), Values(CV_8UC1, CV_8UC3),
Values(Size(5, 5), Size(9, 9)), Values(5, 9),
Values(Size(0, 0)), //not use Values(Size(0, 0)), // not used
Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE, Values((int)BORDER_CONSTANT, (int)BORDER_REPLICATE,
(MatType)cv::BORDER_REFLECT, (MatType)cv::BORDER_WRAP, (MatType)cv::BORDER_REFLECT_101))); (int)BORDER_REFLECT, (int)BORDER_WRAP, (int)BORDER_REFLECT_101),
Values(false))); // TODO does not work with ROI
INSTANTIATE_TEST_CASE_P(Filter, AdaptiveBilateral, Combine( INSTANTIATE_TEST_CASE_P(Filter, AdaptiveBilateral, Combine(
Values(CV_8UC1, CV_8UC3), Values(CV_8UC1, CV_8UC3),
Values(Size(5, 5), Size(9, 9)), Values(5, 9),
Values(Size(0, 0)), //not use Values(Size(0, 0)), // not used
Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE, Values((int)BORDER_CONSTANT, (int)BORDER_REPLICATE,
(MatType)cv::BORDER_REFLECT, (MatType)cv::BORDER_REFLECT_101))); (int)BORDER_REFLECT, (int)BORDER_REFLECT_101),
Bool()));
INSTANTIATE_TEST_CASE_P(Filter, MedianFilter, Combine(
Values((MatType)CV_8UC1, (MatType)CV_8UC4, (MatType)CV_32FC1, (MatType)CV_32FC4),
Values(3, 5),
Values(Size(0, 0)), // not used
Values(0), // not used
Bool()));
#endif // HAVE_OPENCL #endif // HAVE_OPENCL
...@@ -55,9 +55,9 @@ ...@@ -55,9 +55,9 @@
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
using namespace cvtest; using namespace cv;
using namespace testing;
using namespace std; using namespace std;
using namespace testing;
MatType nulltype = -1; MatType nulltype = -1;
...@@ -77,7 +77,7 @@ typedef struct ...@@ -77,7 +77,7 @@ typedef struct
short y; short y;
} COOR; } COOR;
COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep, cv::Size size, int sp, int sr, int maxIter, float eps, int *tab) COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep, Size size, int sp, int sr, int maxIter, float eps, int *tab)
{ {
int isr2 = sr * sr; int isr2 = sr * sr;
...@@ -219,7 +219,7 @@ COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep, cv::Size ...@@ -219,7 +219,7 @@ COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep, cv::Size
return coor; return coor;
} }
void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr, cv::TermCriteria crit) void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr, TermCriteria crit)
{ {
if( src_roi.empty() ) if( src_roi.empty() )
CV_Error( CV_StsBadArg, "The input image is empty" ); CV_Error( CV_StsBadArg, "The input image is empty" );
...@@ -230,11 +230,11 @@ void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr, cv::T ...@@ -230,11 +230,11 @@ void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr, cv::T
CV_Assert( (src_roi.cols == dst_roi.cols) && (src_roi.rows == dst_roi.rows) ); CV_Assert( (src_roi.cols == dst_roi.cols) && (src_roi.rows == dst_roi.rows) );
CV_Assert( !(dst_roi.step & 0x3) ); CV_Assert( !(dst_roi.step & 0x3) );
if( !(crit.type & cv::TermCriteria::MAX_ITER) ) if( !(crit.type & TermCriteria::MAX_ITER) )
crit.maxCount = 5; crit.maxCount = 5;
int maxIter = std::min(std::max(crit.maxCount, 1), 100); int maxIter = std::min(std::max(crit.maxCount, 1), 100);
float eps; float eps;
if( !(crit.type & cv::TermCriteria::EPS) ) if( !(crit.type & TermCriteria::EPS) )
eps = 1.f; eps = 1.f;
eps = (float)std::max(crit.epsilon, 0.0); eps = (float)std::max(crit.epsilon, 0.0);
...@@ -245,7 +245,7 @@ void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr, cv::T ...@@ -245,7 +245,7 @@ void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr, cv::T
uchar *dptr = dst_roi.data; uchar *dptr = dst_roi.data;
int sstep = (int)src_roi.step; int sstep = (int)src_roi.step;
int dstep = (int)dst_roi.step; int dstep = (int)dst_roi.step;
cv::Size size = src_roi.size(); Size size = src_roi.size();
for(int i = 0; i < size.height; i++, sptr += sstep - (size.width << 2), for(int i = 0; i < size.height; i++, sptr += sstep - (size.width << 2),
dptr += dstep - (size.width << 2)) dptr += dstep - (size.width << 2))
...@@ -257,7 +257,7 @@ void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr, cv::T ...@@ -257,7 +257,7 @@ void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr, cv::T
} }
} }
void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp, int sr, cv::TermCriteria crit) void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp, int sr, TermCriteria crit)
{ {
if( src_roi.empty() ) if( src_roi.empty() )
...@@ -268,11 +268,11 @@ void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp, ...@@ -268,11 +268,11 @@ void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp,
(src_roi.cols == dstCoor_roi.cols) && (src_roi.rows == dstCoor_roi.rows)); (src_roi.cols == dstCoor_roi.cols) && (src_roi.rows == dstCoor_roi.rows));
CV_Assert( !(dstCoor_roi.step & 0x3) ); CV_Assert( !(dstCoor_roi.step & 0x3) );
if( !(crit.type & cv::TermCriteria::MAX_ITER) ) if( !(crit.type & TermCriteria::MAX_ITER) )
crit.maxCount = 5; crit.maxCount = 5;
int maxIter = std::min(std::max(crit.maxCount, 1), 100); int maxIter = std::min(std::max(crit.maxCount, 1), 100);
float eps; float eps;
if( !(crit.type & cv::TermCriteria::EPS) ) if( !(crit.type & TermCriteria::EPS) )
eps = 1.f; eps = 1.f;
eps = (float)std::max(crit.epsilon, 0.0); eps = (float)std::max(crit.epsilon, 0.0);
...@@ -285,7 +285,7 @@ void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp, ...@@ -285,7 +285,7 @@ void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp,
int sstep = (int)src_roi.step; int sstep = (int)src_roi.step;
int dstep = (int)dst_roi.step; int dstep = (int)dst_roi.step;
int dCoorstep = (int)dstCoor_roi.step >> 1; int dCoorstep = (int)dstCoor_roi.step >> 1;
cv::Size size = src_roi.size(); Size size = src_roi.size();
for(int i = 0; i < size.height; i++, sptr += sstep - (size.width << 2), for(int i = 0; i < size.height; i++, sptr += sstep - (size.width << 2),
dptr += dstep - (size.width << 2), dCoorptr += dCoorstep - (size.width << 1)) dptr += dstep - (size.width << 2), dCoorptr += dCoorstep - (size.width << 1))
...@@ -301,7 +301,7 @@ void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp, ...@@ -301,7 +301,7 @@ void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp,
PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bool) PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bool)
{ {
int type1, type2, type3, type4, type5; int type1, type2, type3, type4, type5;
cv::Scalar val; Scalar val;
// set up roi // set up roi
int roicols; int roicols;
int roirows; int roirows;
...@@ -317,32 +317,32 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo ...@@ -317,32 +317,32 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo
int masky; int masky;
//mat //mat
cv::Mat mat1; Mat mat1;
cv::Mat mat2; Mat mat2;
cv::Mat mask; Mat mask;
cv::Mat dst; Mat dst;
cv::Mat dst1; //bak, for two outputs Mat dst1; //bak, for two outputs
//mat with roi //mat with roi
cv::Mat mat1_roi; Mat mat1_roi;
cv::Mat mat2_roi; Mat mat2_roi;
cv::Mat mask_roi; Mat mask_roi;
cv::Mat dst_roi; Mat dst_roi;
cv::Mat dst1_roi; //bak Mat dst1_roi; //bak
//ocl mat //ocl mat
cv::ocl::oclMat clmat1; ocl::oclMat clmat1;
cv::ocl::oclMat clmat2; ocl::oclMat clmat2;
cv::ocl::oclMat clmask; ocl::oclMat clmask;
cv::ocl::oclMat cldst; ocl::oclMat cldst;
cv::ocl::oclMat cldst1; //bak ocl::oclMat cldst1; //bak
//ocl mat with roi //ocl mat with roi
cv::ocl::oclMat clmat1_roi; ocl::oclMat clmat1_roi;
cv::ocl::oclMat clmat2_roi; ocl::oclMat clmat2_roi;
cv::ocl::oclMat clmask_roi; ocl::oclMat clmask_roi;
cv::ocl::oclMat cldst_roi; ocl::oclMat cldst_roi;
cv::ocl::oclMat cldst1_roi; ocl::oclMat cldst1_roi;
virtual void SetUp() virtual void SetUp()
{ {
...@@ -351,7 +351,7 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo ...@@ -351,7 +351,7 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo
type3 = GET_PARAM(2); type3 = GET_PARAM(2);
type4 = GET_PARAM(3); type4 = GET_PARAM(3);
type5 = GET_PARAM(4); type5 = GET_PARAM(4);
cv::Size size(MWIDTH, MHEIGHT); Size size(MWIDTH, MHEIGHT);
double min = 1, max = 20; double min = 1, max = 20;
if(type1 != nulltype) if(type1 != nulltype)
...@@ -377,10 +377,10 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo ...@@ -377,10 +377,10 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo
if(type5 != nulltype) if(type5 != nulltype)
{ {
mask = randomMat(size, CV_8UC1, 0, 2, false); mask = randomMat(size, CV_8UC1, 0, 2, false);
cv::threshold(mask, mask, 0.5, 255., type5); threshold(mask, mask, 0.5, 255., type5);
clmask = mask; clmask = mask;
} }
val = cv::Scalar(rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0)); val = Scalar(rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0));
} }
void random_roi() void random_roi()
...@@ -444,16 +444,16 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo ...@@ -444,16 +444,16 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo
void Near(double threshold) void Near(double threshold)
{ {
cv::Mat cpu_cldst; Mat cpu_cldst;
cldst.download(cpu_cldst); cldst.download(cpu_cldst);
EXPECT_MAT_NEAR(dst, cpu_cldst, threshold); EXPECT_MAT_NEAR(dst, cpu_cldst, threshold);
} }
}; };
////////////////////////////////equalizeHist////////////////////////////////////////// ////////////////////////////////equalizeHist//////////////////////////////////////////
struct equalizeHist : ImgprocTestBase {}; typedef ImgprocTestBase EqualizeHist;
OCL_TEST_P(equalizeHist, Mat) OCL_TEST_P(EqualizeHist, Mat)
{ {
if (mat1.type() != CV_8UC1 || mat1.type() != dst.type()) if (mat1.type() != CV_8UC1 || mat1.type() != dst.type())
{ {
...@@ -465,8 +465,8 @@ OCL_TEST_P(equalizeHist, Mat) ...@@ -465,8 +465,8 @@ OCL_TEST_P(equalizeHist, Mat)
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::equalizeHist(mat1_roi, dst_roi); equalizeHist(mat1_roi, dst_roi);
cv::ocl::equalizeHist(clmat1_roi, cldst_roi); ocl::equalizeHist(clmat1_roi, cldst_roi);
Near(1.1); Near(1.1);
} }
} }
...@@ -475,11 +475,11 @@ OCL_TEST_P(equalizeHist, Mat) ...@@ -475,11 +475,11 @@ OCL_TEST_P(equalizeHist, Mat)
////////////////////////////////copyMakeBorder//////////////////////////////////////////// ////////////////////////////////copyMakeBorder////////////////////////////////////////////
struct CopyMakeBorder : ImgprocTestBase {}; typedef ImgprocTestBase CopyMakeBorder;
OCL_TEST_P(CopyMakeBorder, Mat) OCL_TEST_P(CopyMakeBorder, Mat)
{ {
int bordertype[] = {cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT, cv::BORDER_WRAP, cv::BORDER_REFLECT_101}; int bordertype[] = {BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT, BORDER_WRAP, BORDER_REFLECT_101};
int top = rng.uniform(0, 10); int top = rng.uniform(0, 10);
int bottom = rng.uniform(0, 10); int bottom = rng.uniform(0, 10);
int left = rng.uniform(0, 10); int left = rng.uniform(0, 10);
...@@ -496,7 +496,7 @@ OCL_TEST_P(CopyMakeBorder, Mat) ...@@ -496,7 +496,7 @@ OCL_TEST_P(CopyMakeBorder, Mat)
{ {
random_roi(); random_roi();
#ifdef RANDOMROI #ifdef RANDOMROI
if(((bordertype[i] != cv::BORDER_CONSTANT) && (bordertype[i] != cv::BORDER_REPLICATE)) && (mat1_roi.cols <= left) || (mat1_roi.cols <= right) || (mat1_roi.rows <= top) || (mat1_roi.rows <= bottom)) if(((bordertype[i] != BORDER_CONSTANT) && (bordertype[i] != BORDER_REPLICATE)) && (mat1_roi.cols <= left) || (mat1_roi.cols <= right) || (mat1_roi.rows <= top) || (mat1_roi.rows <= bottom))
{ {
continue; continue;
} }
...@@ -510,10 +510,10 @@ OCL_TEST_P(CopyMakeBorder, Mat) ...@@ -510,10 +510,10 @@ OCL_TEST_P(CopyMakeBorder, Mat)
continue; continue;
} }
#endif #endif
cv::copyMakeBorder(mat1_roi, dst_roi, top, bottom, left, right, bordertype[i] | cv::BORDER_ISOLATED, cv::Scalar(1.0)); cv::copyMakeBorder(mat1_roi, dst_roi, top, bottom, left, right, bordertype[i] | BORDER_ISOLATED, Scalar(1.0));
cv::ocl::copyMakeBorder(clmat1_roi, cldst_roi, top, bottom, left, right, bordertype[i] | cv::BORDER_ISOLATED, cv::Scalar(1.0)); ocl::copyMakeBorder(clmat1_roi, cldst_roi, top, bottom, left, right, bordertype[i] | BORDER_ISOLATED, Scalar(1.0));
cv::Mat cpu_cldst; Mat cpu_cldst;
#ifndef RANDOMROI #ifndef RANDOMROI
cldst_roi.download(cpu_cldst); cldst_roi.download(cpu_cldst);
EXPECT_MAT_NEAR(dst_roi, cpu_cldst, 0.0); EXPECT_MAT_NEAR(dst_roi, cpu_cldst, 0.0);
...@@ -530,20 +530,20 @@ OCL_TEST_P(CopyMakeBorder, Mat) ...@@ -530,20 +530,20 @@ OCL_TEST_P(CopyMakeBorder, Mat)
////////////////////////////////cornerMinEigenVal////////////////////////////////////////// ////////////////////////////////cornerMinEigenVal//////////////////////////////////////////
struct cornerMinEigenVal : ImgprocTestBase {}; struct CornerMinEigenVal : ImgprocTestBase {};
OCL_TEST_P(cornerMinEigenVal, Mat) OCL_TEST_P(CornerMinEigenVal, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
int blockSize = 3, apertureSize = 3;//1 + 2 * (rand() % 4); int blockSize = 3, apertureSize = 3;//1 + 2 * (rand() % 4);
//int borderType = cv::BORDER_CONSTANT; //int borderType = BORDER_CONSTANT;
//int borderType = cv::BORDER_REPLICATE; //int borderType = BORDER_REPLICATE;
int borderType = cv::BORDER_REFLECT; int borderType = BORDER_REFLECT;
cv::cornerMinEigenVal(mat1_roi, dst_roi, blockSize, apertureSize, borderType); cornerMinEigenVal(mat1_roi, dst_roi, blockSize, apertureSize, borderType);
cv::ocl::cornerMinEigenVal(clmat1_roi, cldst_roi, blockSize, apertureSize, borderType); ocl::cornerMinEigenVal(clmat1_roi, cldst_roi, blockSize, apertureSize, borderType);
Near(1.); Near(1.);
} }
} }
...@@ -552,9 +552,9 @@ OCL_TEST_P(cornerMinEigenVal, Mat) ...@@ -552,9 +552,9 @@ OCL_TEST_P(cornerMinEigenVal, Mat)
////////////////////////////////cornerHarris////////////////////////////////////////// ////////////////////////////////cornerHarris//////////////////////////////////////////
struct cornerHarris : ImgprocTestBase {}; typedef ImgprocTestBase CornerHarris;
OCL_TEST_P(cornerHarris, Mat) OCL_TEST_P(CornerHarris, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
...@@ -562,11 +562,11 @@ OCL_TEST_P(cornerHarris, Mat) ...@@ -562,11 +562,11 @@ OCL_TEST_P(cornerHarris, Mat)
random_roi(); random_roi();
int blockSize = 3, apertureSize = 3; //1 + 2 * (rand() % 4); int blockSize = 3, apertureSize = 3; //1 + 2 * (rand() % 4);
double k = 2; double k = 2;
//int borderType = cv::BORDER_CONSTANT; //int borderType = BORDER_CONSTANT;
//int borderType = cv::BORDER_REPLICATE; //int borderType = BORDER_REPLICATE;
int borderType = cv::BORDER_REFLECT; int borderType = BORDER_REFLECT;
cv::cornerHarris(mat1_roi, dst_roi, blockSize, apertureSize, k, borderType); cornerHarris(mat1_roi, dst_roi, blockSize, apertureSize, k, borderType);
cv::ocl::cornerHarris(clmat1_roi, cldst_roi, blockSize, apertureSize, k, borderType); ocl::cornerHarris(clmat1_roi, cldst_roi, blockSize, apertureSize, k, borderType);
Near(1.); Near(1.);
} }
} }
...@@ -574,31 +574,31 @@ OCL_TEST_P(cornerHarris, Mat) ...@@ -574,31 +574,31 @@ OCL_TEST_P(cornerHarris, Mat)
////////////////////////////////integral///////////////////////////////////////////////// ////////////////////////////////integral/////////////////////////////////////////////////
struct integral : ImgprocTestBase {}; typedef ImgprocTestBase Integral;
OCL_TEST_P(integral, Mat1) OCL_TEST_P(Integral, Mat1)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::ocl::integral(clmat1_roi, cldst_roi); ocl::integral(clmat1_roi, cldst_roi);
cv::integral(mat1_roi, dst_roi); integral(mat1_roi, dst_roi);
Near(0); Near(0);
} }
} }
OCL_TEST_P(integral, Mat2) OCL_TEST_P(Integral, Mat2)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::ocl::integral(clmat1_roi, cldst_roi, cldst1_roi); ocl::integral(clmat1_roi, cldst_roi, cldst1_roi);
cv::integral(mat1_roi, dst_roi, dst1_roi); integral(mat1_roi, dst_roi, dst1_roi);
Near(0); Near(0);
cv::Mat cpu_cldst1; Mat cpu_cldst1;
cldst1.download(cpu_cldst1); cldst1.download(cpu_cldst1);
EXPECT_MAT_NEAR(dst1, cpu_cldst1, 0.0); EXPECT_MAT_NEAR(dst1, cpu_cldst1, 0.0);
} }
...@@ -611,12 +611,12 @@ OCL_TEST_P(integral, Mat2) ...@@ -611,12 +611,12 @@ OCL_TEST_P(integral, Mat2)
PARAM_TEST_CASE(WarpTestBase, MatType, int) PARAM_TEST_CASE(WarpTestBase, MatType, int)
{ {
int type; int type;
cv::Size size; Size size;
int interpolation; int interpolation;
//src mat //src mat
cv::Mat mat1; Mat mat1;
cv::Mat dst; Mat dst;
// set up roi // set up roi
int src_roicols; int src_roicols;
...@@ -630,21 +630,21 @@ PARAM_TEST_CASE(WarpTestBase, MatType, int) ...@@ -630,21 +630,21 @@ PARAM_TEST_CASE(WarpTestBase, MatType, int)
//src mat with roi //src mat with roi
cv::Mat mat1_roi; Mat mat1_roi;
cv::Mat dst_roi; Mat dst_roi;
//ocl dst mat for testing //ocl dst mat for testing
cv::ocl::oclMat gdst_whole; ocl::oclMat gdst_whole;
//ocl mat with roi //ocl mat with roi
cv::ocl::oclMat gmat1; ocl::oclMat gmat1;
cv::ocl::oclMat gdst; ocl::oclMat gdst;
virtual void SetUp() virtual void SetUp()
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
interpolation = GET_PARAM(1); interpolation = GET_PARAM(1);
size = cv::Size(MWIDTH, MHEIGHT); size = Size(MWIDTH, MHEIGHT);
mat1 = randomMat(size, type, 5, 16, false); mat1 = randomMat(size, type, 5, 16, false);
dst = randomMat(size, type, 5, 16, false); dst = randomMat(size, type, 5, 16, false);
...@@ -688,7 +688,7 @@ PARAM_TEST_CASE(WarpTestBase, MatType, int) ...@@ -688,7 +688,7 @@ PARAM_TEST_CASE(WarpTestBase, MatType, int)
/////warpAffine /////warpAffine
struct WarpAffine : WarpTestBase {}; typedef WarpTestBase WarpAffine;
OCL_TEST_P(WarpAffine, Mat) OCL_TEST_P(WarpAffine, Mat)
{ {
...@@ -703,10 +703,10 @@ OCL_TEST_P(WarpAffine, Mat) ...@@ -703,10 +703,10 @@ OCL_TEST_P(WarpAffine, Mat)
{ {
random_roi(); random_roi();
cv::warpAffine(mat1_roi, dst_roi, M, size, interpolation); warpAffine(mat1_roi, dst_roi, M, size, interpolation);
cv::ocl::warpAffine(gmat1, gdst, M, size, interpolation); ocl::warpAffine(gmat1, gdst, M, size, interpolation);
cv::Mat cpu_dst; Mat cpu_dst;
gdst_whole.download(cpu_dst); gdst_whole.download(cpu_dst);
EXPECT_MAT_NEAR(dst, cpu_dst, 1.0); EXPECT_MAT_NEAR(dst, cpu_dst, 1.0);
} }
...@@ -716,7 +716,7 @@ OCL_TEST_P(WarpAffine, Mat) ...@@ -716,7 +716,7 @@ OCL_TEST_P(WarpAffine, Mat)
// warpPerspective // warpPerspective
struct WarpPerspective : WarpTestBase {}; typedef WarpTestBase WarpPerspective;
OCL_TEST_P(WarpPerspective, Mat) OCL_TEST_P(WarpPerspective, Mat)
{ {
...@@ -732,10 +732,10 @@ OCL_TEST_P(WarpPerspective, Mat) ...@@ -732,10 +732,10 @@ OCL_TEST_P(WarpPerspective, Mat)
{ {
random_roi(); random_roi();
cv::warpPerspective(mat1_roi, dst_roi, M, size, interpolation); warpPerspective(mat1_roi, dst_roi, M, size, interpolation);
cv::ocl::warpPerspective(gmat1, gdst, M, size, interpolation); ocl::warpPerspective(gmat1, gdst, M, size, interpolation);
cv::Mat cpu_dst; Mat cpu_dst;
gdst_whole.download(cpu_dst); gdst_whole.download(cpu_dst);
EXPECT_MAT_NEAR(dst, cpu_dst, 1.0); EXPECT_MAT_NEAR(dst, cpu_dst, 1.0);
} }
...@@ -751,17 +751,17 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int) ...@@ -751,17 +751,17 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
int srcType; int srcType;
int map1Type; int map1Type;
int map2Type; int map2Type;
cv::Scalar val; Scalar val;
int interpolation; int interpolation;
int bordertype; int bordertype;
cv::Mat src; Mat src;
cv::Mat dst; Mat dst;
cv::Mat map1; Mat map1;
cv::Mat map2; Mat map2;
//std::vector<cv::ocl::Info> oclinfo; //std::vector<ocl::Info> oclinfo;
int src_roicols; int src_roicols;
int src_roirows; int src_roirows;
...@@ -780,19 +780,19 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int) ...@@ -780,19 +780,19 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
int map2x; int map2x;
int map2y; int map2y;
cv::Mat src_roi; Mat src_roi;
cv::Mat dst_roi; Mat dst_roi;
cv::Mat map1_roi; Mat map1_roi;
cv::Mat map2_roi; Mat map2_roi;
//ocl mat for testing //ocl mat for testing
cv::ocl::oclMat gdst; ocl::oclMat gdst;
//ocl mat with roi //ocl mat with roi
cv::ocl::oclMat gsrc_roi; ocl::oclMat gsrc_roi;
cv::ocl::oclMat gdst_roi; ocl::oclMat gdst_roi;
cv::ocl::oclMat gmap1_roi; ocl::oclMat gmap1_roi;
cv::ocl::oclMat gmap2_roi; ocl::oclMat gmap2_roi;
virtual void SetUp() virtual void SetUp()
{ {
...@@ -802,8 +802,8 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int) ...@@ -802,8 +802,8 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
interpolation = GET_PARAM(3); interpolation = GET_PARAM(3);
bordertype = GET_PARAM(4); bordertype = GET_PARAM(4);
cv::Size srcSize = cv::Size(MWIDTH, MHEIGHT); Size srcSize = Size(MWIDTH, MHEIGHT);
cv::Size map1Size = cv::Size(MWIDTH, MHEIGHT); Size map1Size = Size(MWIDTH, MHEIGHT);
double min = 5, max = 16; double min = 5, max = 16;
if(srcType != nulltype) if(srcType != nulltype)
...@@ -830,16 +830,16 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int) ...@@ -830,16 +830,16 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
switch (src.channels()) switch (src.channels())
{ {
case 1: case 1:
val = cv::Scalar(rng.uniform(0.0, 10.0), 0, 0, 0); val = Scalar(rng.uniform(0.0, 10.0), 0, 0, 0);
break; break;
case 2: case 2:
val = cv::Scalar(rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), 0, 0); val = Scalar(rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), 0, 0);
break; break;
case 3: case 3:
val = cv::Scalar(rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), 0); val = Scalar(rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), 0);
break; break;
case 4: case 4:
val = cv::Scalar(rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0)); val = Scalar(rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0));
break; break;
} }
...@@ -894,14 +894,14 @@ OCL_TEST_P(Remap, Mat) ...@@ -894,14 +894,14 @@ OCL_TEST_P(Remap, Mat)
cout << "Don't support the dataType" << endl; cout << "Don't support the dataType" << endl;
return; return;
} }
int bordertype[] = {cv::BORDER_CONSTANT, cv::BORDER_REPLICATE/*,BORDER_REFLECT,BORDER_WRAP,BORDER_REFLECT_101*/}; int bordertype[] = {BORDER_CONSTANT, BORDER_REPLICATE/*,BORDER_REFLECT,BORDER_WRAP,BORDER_REFLECT_101*/};
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::remap(src_roi, dst_roi, map1_roi, map2_roi, interpolation, bordertype[0], val); remap(src_roi, dst_roi, map1_roi, map2_roi, interpolation, bordertype[0], val);
cv::ocl::remap(gsrc_roi, gdst_roi, gmap1_roi, gmap2_roi, interpolation, bordertype[0], val); ocl::remap(gsrc_roi, gdst_roi, gmap1_roi, gmap2_roi, interpolation, bordertype[0], val);
cv::Mat cpu_dst; Mat cpu_dst;
gdst.download(cpu_dst); gdst.download(cpu_dst);
if(interpolation == 0) if(interpolation == 0)
...@@ -915,16 +915,16 @@ OCL_TEST_P(Remap, Mat) ...@@ -915,16 +915,16 @@ OCL_TEST_P(Remap, Mat)
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// resize // resize
PARAM_TEST_CASE(Resize, MatType, cv::Size, double, double, int) PARAM_TEST_CASE(Resize, MatType, Size, double, double, int)
{ {
int type; int type;
cv::Size dsize; Size dsize;
double fx, fy; double fx, fy;
int interpolation; int interpolation;
//src mat //src mat
cv::Mat mat1; Mat mat1;
cv::Mat dst; Mat dst;
// set up roi // set up roi
int src_roicols; int src_roicols;
...@@ -937,15 +937,15 @@ PARAM_TEST_CASE(Resize, MatType, cv::Size, double, double, int) ...@@ -937,15 +937,15 @@ PARAM_TEST_CASE(Resize, MatType, cv::Size, double, double, int)
int dsty; int dsty;
//src mat with roi //src mat with roi
cv::Mat mat1_roi; Mat mat1_roi;
cv::Mat dst_roi; Mat dst_roi;
//ocl dst mat for testing //ocl dst mat for testing
cv::ocl::oclMat gdst_whole; ocl::oclMat gdst_whole;
//ocl mat with roi //ocl mat with roi
cv::ocl::oclMat gmat1; ocl::oclMat gmat1;
cv::ocl::oclMat gdst; ocl::oclMat gdst;
virtual void SetUp() virtual void SetUp()
{ {
...@@ -955,15 +955,15 @@ PARAM_TEST_CASE(Resize, MatType, cv::Size, double, double, int) ...@@ -955,15 +955,15 @@ PARAM_TEST_CASE(Resize, MatType, cv::Size, double, double, int)
fy = GET_PARAM(3); fy = GET_PARAM(3);
interpolation = GET_PARAM(4); interpolation = GET_PARAM(4);
cv::Size size(MWIDTH, MHEIGHT); Size size(MWIDTH, MHEIGHT);
if(dsize == cv::Size() && !(fx > 0 && fy > 0)) if(dsize == Size() && !(fx > 0 && fy > 0))
{ {
cout << "invalid dsize and fx fy" << endl; cout << "invalid dsize and fx fy" << endl;
return; return;
} }
if(dsize == cv::Size()) if(dsize == Size())
{ {
dsize.width = (int)(size.width * fx); dsize.width = (int)(size.width * fx);
dsize.height = (int)(size.height * fy); dsize.height = (int)(size.height * fy);
...@@ -1018,13 +1018,13 @@ OCL_TEST_P(Resize, Mat) ...@@ -1018,13 +1018,13 @@ OCL_TEST_P(Resize, Mat)
{ {
random_roi(); random_roi();
// cv::resize(mat1_roi, dst_roi, dsize, fx, fy, interpolation); // resize(mat1_roi, dst_roi, dsize, fx, fy, interpolation);
// cv::ocl::resize(gmat1, gdst, dsize, fx, fy, interpolation); // ocl::resize(gmat1, gdst, dsize, fx, fy, interpolation);
if(dst_roicols < 1 || dst_roirows < 1) continue; if(dst_roicols < 1 || dst_roirows < 1) continue;
cv::resize(mat1_roi, dst_roi, dsize, fx, fy, interpolation); resize(mat1_roi, dst_roi, dsize, fx, fy, interpolation);
cv::ocl::resize(gmat1, gdst, dsize, fx, fy, interpolation); ocl::resize(gmat1, gdst, dsize, fx, fy, interpolation);
cv::Mat cpu_dst; Mat cpu_dst;
gdst_whole.download(cpu_dst); gdst_whole.download(cpu_dst);
EXPECT_MAT_NEAR(dst, cpu_dst, 1.0); EXPECT_MAT_NEAR(dst, cpu_dst, 1.0);
} }
...@@ -1041,8 +1041,8 @@ PARAM_TEST_CASE(Threshold, MatType, ThreshOp) ...@@ -1041,8 +1041,8 @@ PARAM_TEST_CASE(Threshold, MatType, ThreshOp)
int threshOp; int threshOp;
//src mat //src mat
cv::Mat mat1; Mat mat1;
cv::Mat dst; Mat dst;
// set up roi // set up roi
int roicols; int roicols;
...@@ -1053,22 +1053,22 @@ PARAM_TEST_CASE(Threshold, MatType, ThreshOp) ...@@ -1053,22 +1053,22 @@ PARAM_TEST_CASE(Threshold, MatType, ThreshOp)
int dsty; int dsty;
//src mat with roi //src mat with roi
cv::Mat mat1_roi; Mat mat1_roi;
cv::Mat dst_roi; Mat dst_roi;
//ocl dst mat for testing //ocl dst mat for testing
cv::ocl::oclMat gdst_whole; ocl::oclMat gdst_whole;
//ocl mat with roi //ocl mat with roi
cv::ocl::oclMat gmat1; ocl::oclMat gmat1;
cv::ocl::oclMat gdst; ocl::oclMat gdst;
virtual void SetUp() virtual void SetUp()
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
threshOp = GET_PARAM(1); threshOp = GET_PARAM(1);
cv::Size size(MWIDTH, MHEIGHT); Size size(MWIDTH, MHEIGHT);
mat1 = randomMat(size, type, 5, 16, false); mat1 = randomMat(size, type, 5, 16, false);
dst = randomMat(size, type, 5, 16, false); dst = randomMat(size, type, 5, 16, false);
...@@ -1113,25 +1113,25 @@ OCL_TEST_P(Threshold, Mat) ...@@ -1113,25 +1113,25 @@ OCL_TEST_P(Threshold, Mat)
double maxVal = randomDouble(20.0, 127.0); double maxVal = randomDouble(20.0, 127.0);
double thresh = randomDouble(0.0, maxVal); double thresh = randomDouble(0.0, maxVal);
cv::threshold(mat1_roi, dst_roi, thresh, maxVal, threshOp); threshold(mat1_roi, dst_roi, thresh, maxVal, threshOp);
cv::ocl::threshold(gmat1, gdst, thresh, maxVal, threshOp); ocl::threshold(gmat1, gdst, thresh, maxVal, threshOp);
cv::Mat cpu_dst; Mat cpu_dst;
gdst_whole.download(cpu_dst); gdst_whole.download(cpu_dst);
EXPECT_MAT_NEAR(dst, cpu_dst, 1); EXPECT_MAT_NEAR(dst, cpu_dst, 1);
} }
} }
PARAM_TEST_CASE(meanShiftTestBase, MatType, MatType, int, int, cv::TermCriteria) PARAM_TEST_CASE(MeanShiftTestBase, MatType, MatType, int, int, TermCriteria)
{ {
int type, typeCoor; int type, typeCoor;
int sp, sr; int sp, sr;
cv::TermCriteria crit; TermCriteria crit;
//src mat //src mat
cv::Mat src; Mat src;
cv::Mat dst; Mat dst;
cv::Mat dstCoor; Mat dstCoor;
//set up roi //set up roi
int roicols; int roicols;
...@@ -1142,18 +1142,18 @@ PARAM_TEST_CASE(meanShiftTestBase, MatType, MatType, int, int, cv::TermCriteria) ...@@ -1142,18 +1142,18 @@ PARAM_TEST_CASE(meanShiftTestBase, MatType, MatType, int, int, cv::TermCriteria)
int dsty; int dsty;
//src mat with roi //src mat with roi
cv::Mat src_roi; Mat src_roi;
cv::Mat dst_roi; Mat dst_roi;
cv::Mat dstCoor_roi; Mat dstCoor_roi;
//ocl dst mat //ocl dst mat
cv::ocl::oclMat gdst; ocl::oclMat gdst;
cv::ocl::oclMat gdstCoor; ocl::oclMat gdstCoor;
//ocl mat with roi //ocl mat with roi
cv::ocl::oclMat gsrc_roi; ocl::oclMat gsrc_roi;
cv::ocl::oclMat gdst_roi; ocl::oclMat gdst_roi;
cv::ocl::oclMat gdstCoor_roi; ocl::oclMat gdstCoor_roi;
virtual void SetUp() virtual void SetUp()
{ {
...@@ -1164,7 +1164,7 @@ PARAM_TEST_CASE(meanShiftTestBase, MatType, MatType, int, int, cv::TermCriteria) ...@@ -1164,7 +1164,7 @@ PARAM_TEST_CASE(meanShiftTestBase, MatType, MatType, int, int, cv::TermCriteria)
crit = GET_PARAM(4); crit = GET_PARAM(4);
// MWIDTH=256, MHEIGHT=256. defined in utility.hpp // MWIDTH=256, MHEIGHT=256. defined in utility.hpp
cv::Size size = cv::Size(MWIDTH, MHEIGHT); Size size = Size(MWIDTH, MHEIGHT);
src = randomMat(size, type, 5, 16, false); src = randomMat(size, type, 5, 16, false);
dst = randomMat(size, type, 5, 16, false); dst = randomMat(size, type, 5, 16, false);
...@@ -1204,20 +1204,21 @@ PARAM_TEST_CASE(meanShiftTestBase, MatType, MatType, int, int, cv::TermCriteria) ...@@ -1204,20 +1204,21 @@ PARAM_TEST_CASE(meanShiftTestBase, MatType, MatType, int, int, cv::TermCriteria)
}; };
/////////////////////////meanShiftFiltering///////////////////////////// /////////////////////////meanShiftFiltering/////////////////////////////
struct meanShiftFiltering : meanShiftTestBase {};
OCL_TEST_P(meanShiftFiltering, Mat) typedef MeanShiftTestBase MeanShiftFiltering;
OCL_TEST_P(MeanShiftFiltering, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::Mat cpu_gdst; Mat cpu_gdst;
gdst.download(cpu_gdst); gdst.download(cpu_gdst);
meanShiftFiltering_(src_roi, dst_roi, sp, sr, crit); ::meanShiftFiltering_(src_roi, dst_roi, sp, sr, crit);
cv::ocl::meanShiftFiltering(gsrc_roi, gdst_roi, sp, sr, crit); ocl::meanShiftFiltering(gsrc_roi, gdst_roi, sp, sr, crit);
gdst.download(cpu_gdst); gdst.download(cpu_gdst);
EXPECT_MAT_NEAR(dst, cpu_gdst, 0.0); EXPECT_MAT_NEAR(dst, cpu_gdst, 0.0);
...@@ -1225,20 +1226,21 @@ OCL_TEST_P(meanShiftFiltering, Mat) ...@@ -1225,20 +1226,21 @@ OCL_TEST_P(meanShiftFiltering, Mat)
} }
///////////////////////////meanShiftProc////////////////////////////////// ///////////////////////////meanShiftProc//////////////////////////////////
struct meanShiftProc : meanShiftTestBase {};
OCL_TEST_P(meanShiftProc, Mat) typedef MeanShiftTestBase MeanShiftProc;
OCL_TEST_P(MeanShiftProc, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::Mat cpu_gdst; Mat cpu_gdst;
cv::Mat cpu_gdstCoor; Mat cpu_gdstCoor;
meanShiftProc_(src_roi, dst_roi, dstCoor_roi, sp, sr, crit); meanShiftProc_(src_roi, dst_roi, dstCoor_roi, sp, sr, crit);
cv::ocl::meanShiftProc(gsrc_roi, gdst_roi, gdstCoor_roi, sp, sr, crit); ocl::meanShiftProc(gsrc_roi, gdst_roi, gdstCoor_roi, sp, sr, crit);
gdst.download(cpu_gdst); gdst.download(cpu_gdst);
gdstCoor.download(cpu_gdstCoor); gdstCoor.download(cpu_gdstCoor);
...@@ -1249,10 +1251,11 @@ OCL_TEST_P(meanShiftProc, Mat) ...@@ -1249,10 +1251,11 @@ OCL_TEST_P(meanShiftProc, Mat)
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
//hist //hist
void calcHistGold(const cv::Mat &src, cv::Mat &hist)
void calcHistGold(const Mat &src, Mat &hist)
{ {
hist.create(1, 256, CV_32SC1); hist.create(1, 256, CV_32SC1);
hist.setTo(cv::Scalar::all(0)); hist.setTo(Scalar::all(0));
int *hist_row = hist.ptr<int>(); int *hist_row = hist.ptr<int>();
for (int y = 0; y < src.rows; ++y) for (int y = 0; y < src.rows; ++y)
...@@ -1264,30 +1267,30 @@ void calcHistGold(const cv::Mat &src, cv::Mat &hist) ...@@ -1264,30 +1267,30 @@ void calcHistGold(const cv::Mat &src, cv::Mat &hist)
} }
} }
PARAM_TEST_CASE(histTestBase, MatType, MatType) PARAM_TEST_CASE(HistTestBase, MatType, MatType)
{ {
int type_src; int type_src;
//src mat //src mat
cv::Mat src; Mat src;
cv::Mat dst_hist; Mat dst_hist;
//set up roi //set up roi
int roicols; int roicols;
int roirows; int roirows;
int srcx; int srcx;
int srcy; int srcy;
//src mat with roi //src mat with roi
cv::Mat src_roi; Mat src_roi;
//ocl dst mat, dst_hist and gdst_hist don't have roi //ocl dst mat, dst_hist and gdst_hist don't have roi
cv::ocl::oclMat gdst_hist; ocl::oclMat gdst_hist;
//ocl mat with roi //ocl mat with roi
cv::ocl::oclMat gsrc_roi; ocl::oclMat gsrc_roi;
virtual void SetUp() virtual void SetUp()
{ {
type_src = GET_PARAM(0); type_src = GET_PARAM(0);
cv::Size size = cv::Size(MWIDTH, MHEIGHT); Size size = Size(MWIDTH, MHEIGHT);
src = randomMat(size, type_src, 0, 256, false); src = randomMat(size, type_src, 0, 256, false);
...@@ -1312,69 +1315,73 @@ PARAM_TEST_CASE(histTestBase, MatType, MatType) ...@@ -1312,69 +1315,73 @@ PARAM_TEST_CASE(histTestBase, MatType, MatType)
gsrc_roi = src_roi; gsrc_roi = src_roi;
} }
}; };
///////////////////////////calcHist/////////////////////////////////////// ///////////////////////////calcHist///////////////////////////////////////
struct calcHist : histTestBase {};
OCL_TEST_P(calcHist, Mat) typedef HistTestBase CalcHist;
OCL_TEST_P(CalcHist, Mat)
{ {
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::Mat cpu_hist; Mat cpu_hist;
calcHistGold(src_roi, dst_hist); calcHistGold(src_roi, dst_hist);
cv::ocl::calcHist(gsrc_roi, gdst_hist); ocl::calcHist(gsrc_roi, gdst_hist);
gdst_hist.download(cpu_hist); gdst_hist.download(cpu_hist);
EXPECT_MAT_NEAR(dst_hist, cpu_hist, 0.0); EXPECT_MAT_NEAR(dst_hist, cpu_hist, 0.0);
} }
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
// CLAHE // CLAHE
PARAM_TEST_CASE(CLAHE, cv::Size, double) PARAM_TEST_CASE(CLAHE_Test, Size, double)
{ {
cv::Size gridSize; Size gridSize;
double clipLimit; double clipLimit;
cv::Mat src; Mat src;
cv::Mat dst_gold; Mat dst_gold;
cv::ocl::oclMat g_src; ocl::oclMat g_src;
cv::ocl::oclMat g_dst; ocl::oclMat g_dst;
virtual void SetUp() virtual void SetUp()
{ {
gridSize = GET_PARAM(0); gridSize = GET_PARAM(0);
clipLimit = GET_PARAM(1); clipLimit = GET_PARAM(1);
src = randomMat(cv::Size(MWIDTH, MHEIGHT), CV_8UC1, 0, 256, false); src = randomMat(Size(MWIDTH, MHEIGHT), CV_8UC1, 0, 256, false);
g_src.upload(src); g_src.upload(src);
} }
}; };
OCL_TEST_P(CLAHE, Accuracy) OCL_TEST_P(CLAHE_Test, Accuracy)
{ {
cv::Ptr<cv::CLAHE> clahe = cv::ocl::createCLAHE(clipLimit, gridSize); Ptr<CLAHE> clahe = ocl::createCLAHE(clipLimit, gridSize);
clahe->apply(g_src, g_dst); clahe->apply(g_src, g_dst);
cv::Mat dst(g_dst); Mat dst(g_dst);
cv::Ptr<cv::CLAHE> clahe_gold = cv::createCLAHE(clipLimit, gridSize); Ptr<CLAHE> clahe_gold = createCLAHE(clipLimit, gridSize);
clahe_gold->apply(src, dst_gold); clahe_gold->apply(src, dst_gold);
EXPECT_MAT_NEAR(dst_gold, dst, 1.0); EXPECT_MAT_NEAR(dst_gold, dst, 1.0);
} }
///////////////////////////Convolve////////////////////////////////// ///////////////////////////Convolve//////////////////////////////////
PARAM_TEST_CASE(ConvolveTestBase, MatType, bool) PARAM_TEST_CASE(ConvolveTestBase, MatType, bool)
{ {
int type; int type;
//src mat //src mat
cv::Mat mat1; Mat mat1;
cv::Mat mat2; Mat mat2;
cv::Mat dst; Mat dst;
cv::Mat dst1; //bak, for two outputs Mat dst1; //bak, for two outputs
// set up roi // set up roi
int roicols; int roicols;
int roirows; int roirows;
...@@ -1385,23 +1392,23 @@ PARAM_TEST_CASE(ConvolveTestBase, MatType, bool) ...@@ -1385,23 +1392,23 @@ PARAM_TEST_CASE(ConvolveTestBase, MatType, bool)
int dstx; int dstx;
int dsty; int dsty;
//src mat with roi //src mat with roi
cv::Mat mat1_roi; Mat mat1_roi;
cv::Mat mat2_roi; Mat mat2_roi;
cv::Mat dst_roi; Mat dst_roi;
cv::Mat dst1_roi; //bak Mat dst1_roi; //bak
//ocl dst mat for testing //ocl dst mat for testing
cv::ocl::oclMat gdst_whole; ocl::oclMat gdst_whole;
cv::ocl::oclMat gdst1_whole; //bak ocl::oclMat gdst1_whole; //bak
//ocl mat with roi //ocl mat with roi
cv::ocl::oclMat gmat1; ocl::oclMat gmat1;
cv::ocl::oclMat gmat2; ocl::oclMat gmat2;
cv::ocl::oclMat gdst; ocl::oclMat gdst;
cv::ocl::oclMat gdst1; //bak ocl::oclMat gdst1; //bak
virtual void SetUp() virtual void SetUp()
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
cv::Size size(MWIDTH, MHEIGHT); Size size(MWIDTH, MHEIGHT);
mat1 = randomMat(size, type, 5, 16, false); mat1 = randomMat(size, type, 5, 16, false);
mat2 = randomMat(size, type, 5, 16, false); mat2 = randomMat(size, type, 5, 16, false);
...@@ -1445,9 +1452,10 @@ PARAM_TEST_CASE(ConvolveTestBase, MatType, bool) ...@@ -1445,9 +1452,10 @@ PARAM_TEST_CASE(ConvolveTestBase, MatType, bool)
} }
}; };
struct Convolve : ConvolveTestBase {};
void conv2( cv::Mat x, cv::Mat y, cv::Mat z) typedef ConvolveTestBase Convolve;
void conv2( Mat x, Mat y, Mat z)
{ {
int N1 = x.rows; int N1 = x.rows;
int M1 = x.cols; int M1 = x.cols;
...@@ -1477,6 +1485,7 @@ void conv2( cv::Mat x, cv::Mat y, cv::Mat z) ...@@ -1477,6 +1485,7 @@ void conv2( cv::Mat x, cv::Mat y, cv::Mat z)
dstdata[i * (z.step >> 2) + j] = temp; dstdata[i * (z.step >> 2) + j] = temp;
} }
} }
OCL_TEST_P(Convolve, Mat) OCL_TEST_P(Convolve, Mat)
{ {
if(mat1.type() != CV_32FC1) if(mat1.type() != CV_32FC1)
...@@ -1486,14 +1495,14 @@ OCL_TEST_P(Convolve, Mat) ...@@ -1486,14 +1495,14 @@ OCL_TEST_P(Convolve, Mat)
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
random_roi(); random_roi();
cv::ocl::oclMat temp1; ocl::oclMat temp1;
cv::Mat kernel_cpu = mat2(Rect(0, 0, 7, 7)); Mat kernel_cpu = mat2(Rect(0, 0, 7, 7));
temp1 = kernel_cpu; temp1 = kernel_cpu;
conv2(kernel_cpu, mat1_roi, dst_roi); conv2(kernel_cpu, mat1_roi, dst_roi);
cv::ocl::convolve(gmat1, temp1, gdst); ocl::convolve(gmat1, temp1, gdst);
cv::Mat cpu_dst; Mat cpu_dst;
gdst_whole.download(cpu_dst); gdst_whole.download(cpu_dst);
EXPECT_MAT_NEAR(dst, cpu_dst, .1); EXPECT_MAT_NEAR(dst, cpu_dst, .1);
...@@ -1501,10 +1510,11 @@ OCL_TEST_P(Convolve, Mat) ...@@ -1501,10 +1510,11 @@ OCL_TEST_P(Convolve, Mat)
} }
//////////////////////////////// ColumnSum ////////////////////////////////////// //////////////////////////////// ColumnSum //////////////////////////////////////
PARAM_TEST_CASE(ColumnSum, cv::Size)
PARAM_TEST_CASE(ColumnSum, Size)
{ {
cv::Size size; Size size;
cv::Mat src; Mat src;
virtual void SetUp() virtual void SetUp()
{ {
...@@ -1514,13 +1524,13 @@ PARAM_TEST_CASE(ColumnSum, cv::Size) ...@@ -1514,13 +1524,13 @@ PARAM_TEST_CASE(ColumnSum, cv::Size)
OCL_TEST_P(ColumnSum, Accuracy) OCL_TEST_P(ColumnSum, Accuracy)
{ {
cv::Mat src = randomMat(size, CV_32FC1, 0, 255); Mat src = randomMat(size, CV_32FC1, 0, 255);
cv::ocl::oclMat d_dst; ocl::oclMat d_dst;
cv::ocl::oclMat d_src(src); ocl::oclMat d_src(src);
cv::ocl::columnSum(d_src, d_dst); ocl::columnSum(d_src, d_dst);
cv::Mat dst(d_dst); Mat dst(d_dst);
for (int j = 0; j < src.cols; ++j) for (int j = 0; j < src.cols; ++j)
{ {
...@@ -1539,9 +1549,10 @@ OCL_TEST_P(ColumnSum, Accuracy) ...@@ -1539,9 +1549,10 @@ OCL_TEST_P(ColumnSum, Accuracy)
} }
} }
} }
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
INSTANTIATE_TEST_CASE_P(ImgprocTestBase, equalizeHist, Combine( INSTANTIATE_TEST_CASE_P(ImgprocTestBase, EqualizeHist, Combine(
ONE_TYPE(CV_8UC1), ONE_TYPE(CV_8UC1),
NULL_TYPE, NULL_TYPE,
ONE_TYPE(CV_8UC1), ONE_TYPE(CV_8UC1),
...@@ -1558,7 +1569,7 @@ INSTANTIATE_TEST_CASE_P(ImgprocTestBase, CopyMakeBorder, Combine( ...@@ -1558,7 +1569,7 @@ INSTANTIATE_TEST_CASE_P(ImgprocTestBase, CopyMakeBorder, Combine(
NULL_TYPE, NULL_TYPE,
Values(false))); // Values(false) is the reserved parameter Values(false))); // Values(false) is the reserved parameter
INSTANTIATE_TEST_CASE_P(ImgprocTestBase, cornerMinEigenVal, Combine( INSTANTIATE_TEST_CASE_P(ImgprocTestBase, CornerMinEigenVal, Combine(
Values(CV_8UC1, CV_32FC1), Values(CV_8UC1, CV_32FC1),
NULL_TYPE, NULL_TYPE,
ONE_TYPE(CV_32FC1), ONE_TYPE(CV_32FC1),
...@@ -1566,7 +1577,7 @@ INSTANTIATE_TEST_CASE_P(ImgprocTestBase, cornerMinEigenVal, Combine( ...@@ -1566,7 +1577,7 @@ INSTANTIATE_TEST_CASE_P(ImgprocTestBase, cornerMinEigenVal, Combine(
NULL_TYPE, NULL_TYPE,
Values(false))); // Values(false) is the reserved parameter Values(false))); // Values(false) is the reserved parameter
INSTANTIATE_TEST_CASE_P(ImgprocTestBase, cornerHarris, Combine( INSTANTIATE_TEST_CASE_P(ImgprocTestBase, CornerHarris, Combine(
Values(CV_8UC1, CV_32FC1), Values(CV_8UC1, CV_32FC1),
NULL_TYPE, NULL_TYPE,
ONE_TYPE(CV_32FC1), ONE_TYPE(CV_32FC1),
...@@ -1575,7 +1586,7 @@ INSTANTIATE_TEST_CASE_P(ImgprocTestBase, cornerHarris, Combine( ...@@ -1575,7 +1586,7 @@ INSTANTIATE_TEST_CASE_P(ImgprocTestBase, cornerHarris, Combine(
Values(false))); // Values(false) is the reserved parameter Values(false))); // Values(false) is the reserved parameter
INSTANTIATE_TEST_CASE_P(ImgprocTestBase, integral, Combine( INSTANTIATE_TEST_CASE_P(ImgprocTestBase, Integral, Combine(
ONE_TYPE(CV_8UC1), ONE_TYPE(CV_8UC1),
NULL_TYPE, NULL_TYPE,
ONE_TYPE(CV_32SC1), ONE_TYPE(CV_32SC1),
...@@ -1585,60 +1596,60 @@ INSTANTIATE_TEST_CASE_P(ImgprocTestBase, integral, Combine( ...@@ -1585,60 +1596,60 @@ INSTANTIATE_TEST_CASE_P(ImgprocTestBase, integral, Combine(
INSTANTIATE_TEST_CASE_P(Imgproc, WarpAffine, Combine( INSTANTIATE_TEST_CASE_P(Imgproc, WarpAffine, Combine(
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
Values((MatType)cv::INTER_NEAREST, (MatType)cv::INTER_LINEAR, Values((MatType)INTER_NEAREST, (MatType)INTER_LINEAR,
(MatType)cv::INTER_CUBIC, (MatType)(cv::INTER_NEAREST | cv::WARP_INVERSE_MAP), (MatType)INTER_CUBIC, (MatType)(INTER_NEAREST | WARP_INVERSE_MAP),
(MatType)(cv::INTER_LINEAR | cv::WARP_INVERSE_MAP), (MatType)(cv::INTER_CUBIC | cv::WARP_INVERSE_MAP)))); (MatType)(INTER_LINEAR | WARP_INVERSE_MAP), (MatType)(INTER_CUBIC | WARP_INVERSE_MAP))));
INSTANTIATE_TEST_CASE_P(Imgproc, WarpPerspective, Combine INSTANTIATE_TEST_CASE_P(Imgproc, WarpPerspective, Combine
(Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), (Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
Values((MatType)cv::INTER_NEAREST, (MatType)cv::INTER_LINEAR, Values((MatType)INTER_NEAREST, (MatType)INTER_LINEAR,
(MatType)cv::INTER_CUBIC, (MatType)(cv::INTER_NEAREST | cv::WARP_INVERSE_MAP), (MatType)INTER_CUBIC, (MatType)(INTER_NEAREST | WARP_INVERSE_MAP),
(MatType)(cv::INTER_LINEAR | cv::WARP_INVERSE_MAP), (MatType)(cv::INTER_CUBIC | cv::WARP_INVERSE_MAP)))); (MatType)(INTER_LINEAR | WARP_INVERSE_MAP), (MatType)(INTER_CUBIC | WARP_INVERSE_MAP))));
INSTANTIATE_TEST_CASE_P(Imgproc, Resize, Combine( INSTANTIATE_TEST_CASE_P(Imgproc, Resize, Combine(
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), Values(cv::Size()), Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), Values(Size()),
Values(0.5, 1.5, 2), Values(0.5, 1.5, 2), Values((MatType)cv::INTER_NEAREST, (MatType)cv::INTER_LINEAR))); Values(0.5, 1.5, 2), Values(0.5, 1.5, 2), Values((MatType)INTER_NEAREST, (MatType)INTER_LINEAR)));
INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine( INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine(
Values(CV_8UC1, CV_32FC1), Values(ThreshOp(cv::THRESH_BINARY), Values(CV_8UC1, CV_32FC1), Values(ThreshOp(THRESH_BINARY),
ThreshOp(cv::THRESH_BINARY_INV), ThreshOp(cv::THRESH_TRUNC), ThreshOp(THRESH_BINARY_INV), ThreshOp(THRESH_TRUNC),
ThreshOp(cv::THRESH_TOZERO), ThreshOp(cv::THRESH_TOZERO_INV)))); ThreshOp(THRESH_TOZERO), ThreshOp(THRESH_TOZERO_INV))));
INSTANTIATE_TEST_CASE_P(Imgproc, meanShiftFiltering, Combine( INSTANTIATE_TEST_CASE_P(Imgproc, MeanShiftFiltering, Combine(
ONE_TYPE(CV_8UC4), ONE_TYPE(CV_8UC4),
ONE_TYPE(CV_16SC2), ONE_TYPE(CV_16SC2),
Values(5), Values(5),
Values(6), Values(6),
Values(cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 5, 1)) Values(TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 5, 1))
)); ));
INSTANTIATE_TEST_CASE_P(Imgproc, meanShiftProc, Combine( INSTANTIATE_TEST_CASE_P(Imgproc, MeanShiftProc, Combine(
ONE_TYPE(CV_8UC4), ONE_TYPE(CV_8UC4),
ONE_TYPE(CV_16SC2), ONE_TYPE(CV_16SC2),
Values(5), Values(5),
Values(6), Values(6),
Values(cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 5, 1)) Values(TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 5, 1))
)); ));
INSTANTIATE_TEST_CASE_P(Imgproc, Remap, Combine( INSTANTIATE_TEST_CASE_P(Imgproc, Remap, Combine(
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
Values(CV_32FC1, CV_16SC2, CV_32FC2), Values(-1, CV_32FC1), Values(CV_32FC1, CV_16SC2, CV_32FC2), Values(-1, CV_32FC1),
Values((int)cv::INTER_NEAREST, (int)cv::INTER_LINEAR), Values((int)INTER_NEAREST, (int)INTER_LINEAR),
Values((int)cv::BORDER_CONSTANT))); Values((int)BORDER_CONSTANT)));
INSTANTIATE_TEST_CASE_P(histTestBase, calcHist, Combine( INSTANTIATE_TEST_CASE_P(histTestBase, CalcHist, Combine(
ONE_TYPE(CV_8UC1), ONE_TYPE(CV_8UC1),
ONE_TYPE(CV_32SC1) //no use ONE_TYPE(CV_32SC1) //no use
)); ));
INSTANTIATE_TEST_CASE_P(Imgproc, CLAHE, Combine( INSTANTIATE_TEST_CASE_P(Imgproc, CLAHE_Test, Combine(
Values(cv::Size(4, 4), cv::Size(32, 8), cv::Size(8, 64)), Values(Size(4, 4), Size(32, 8), Size(8, 64)),
Values(0.0, 10.0, 62.0, 300.0))); Values(0.0, 10.0, 62.0, 300.0)));
INSTANTIATE_TEST_CASE_P(Imgproc, ColumnSum, DIFFERENT_SIZES); INSTANTIATE_TEST_CASE_P(Imgproc, ColumnSum, DIFFERENT_SIZES);
......
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