added cn>1 support to cv::norm (NORM_INF)
This commit is contained in:
parent
dacf63a888
commit
c80faff42f
@ -50,6 +50,36 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined OP_NORM_INF_MASK || defined OP_MIN_MAX_LOC || defined OP_MIN_MAX_LOC_MASK
|
||||
|
||||
#ifdef DEPTH_0
|
||||
#define MIN_VAL 0
|
||||
#define MAX_VAL 255
|
||||
#elif defined DEPTH_1
|
||||
#define MIN_VAL -128
|
||||
#define MAX_VAL 127
|
||||
#elif defined DEPTH_2
|
||||
#define MIN_VAL 0
|
||||
#define MAX_VAL 65535
|
||||
#elif defined DEPTH_3
|
||||
#define MIN_VAL -32768
|
||||
#define MAX_VAL 32767
|
||||
#elif defined DEPTH_4
|
||||
#define MIN_VAL INT_MIN
|
||||
#define MAX_VAL INT_MAX
|
||||
#elif defined DEPTH_5
|
||||
#define MIN_VAL (-FLT_MAX)
|
||||
#define MAX_VAL FLT_MAX
|
||||
#elif defined DEPTH_6
|
||||
#define MIN_VAL (-DBL_MAX)
|
||||
#define MAX_VAL DBL_MAX
|
||||
#endif
|
||||
|
||||
#define dstT srcT
|
||||
#define dstT1 srcT1
|
||||
|
||||
#endif // min/max stuff
|
||||
|
||||
#define noconvert
|
||||
|
||||
#if cn != 3
|
||||
@ -145,41 +175,32 @@
|
||||
#define CALC_RESULT \
|
||||
storepix(localmem[0], dstptr + dstTSIZE * gid)
|
||||
|
||||
// norm (NORM_INF) with cn > 1 and mask
|
||||
#elif defined OP_NORM_INF_MASK
|
||||
|
||||
#define DECLARE_LOCAL_MEM \
|
||||
__local srcT localmem_max[WGS2_ALIGNED]
|
||||
#define DEFINE_ACCUMULATOR \
|
||||
srcT maxval = MIN_VAL, temp
|
||||
#define REDUCE_GLOBAL \
|
||||
int mask_index = mad24(id / cols, mask_step, mask_offset + (id % cols)); \
|
||||
if (mask[mask_index]) \
|
||||
{ \
|
||||
temp = loadpix(srcptr + src_index); \
|
||||
maxval = max(maxval, (srcT)(temp >= 0 ? temp : -temp)); \
|
||||
}
|
||||
#define SET_LOCAL_1 \
|
||||
localmem_max[lid] = maxval
|
||||
#define REDUCE_LOCAL_1 \
|
||||
localmem_max[lid - WGS2_ALIGNED] = max(maxval, localmem_max[lid - WGS2_ALIGNED])
|
||||
#define REDUCE_LOCAL_2 \
|
||||
localmem_max[lid] = max(localmem_max[lid], localmem_max[lid2])
|
||||
#define CALC_RESULT \
|
||||
storepix(localmem_max[0], dstptr + dstTSIZE * gid)
|
||||
|
||||
// minMaxLoc stuff
|
||||
#elif defined OP_MIN_MAX_LOC || defined OP_MIN_MAX_LOC_MASK
|
||||
|
||||
#ifdef DEPTH_0
|
||||
#define srcT uchar
|
||||
#define MIN_VAL 0
|
||||
#define MAX_VAL 255
|
||||
#elif defined DEPTH_1
|
||||
#define srcT char
|
||||
#define MIN_VAL -128
|
||||
#define MAX_VAL 127
|
||||
#elif defined DEPTH_2
|
||||
#define srcT ushort
|
||||
#define MIN_VAL 0
|
||||
#define MAX_VAL 65535
|
||||
#elif defined DEPTH_3
|
||||
#define srcT short
|
||||
#define MIN_VAL -32768
|
||||
#define MAX_VAL 32767
|
||||
#elif defined DEPTH_4
|
||||
#define srcT int
|
||||
#define MIN_VAL INT_MIN
|
||||
#define MAX_VAL INT_MAX
|
||||
#elif defined DEPTH_5
|
||||
#define srcT float
|
||||
#define MIN_VAL (-FLT_MAX)
|
||||
#define MAX_VAL FLT_MAX
|
||||
#elif defined DEPTH_6
|
||||
#define srcT double
|
||||
#define MIN_VAL (-DBL_MAX)
|
||||
#define MAX_VAL DBL_MAX
|
||||
#endif
|
||||
|
||||
#define dstT srcT
|
||||
|
||||
#define DECLARE_LOCAL_MEM \
|
||||
__local srcT localmem_min[WGS2_ALIGNED]; \
|
||||
__local srcT localmem_max[WGS2_ALIGNED]; \
|
||||
|
@ -41,10 +41,11 @@
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencl_kernels.hpp"
|
||||
#include <climits>
|
||||
#include <limits>
|
||||
|
||||
#include "opencl_kernels.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
@ -1300,8 +1301,9 @@ static bool ocl_minMaxIdx( InputArray _src, double* minVal, double* maxVal, int*
|
||||
wgs2_aligned <<= 1;
|
||||
wgs2_aligned >>= 1;
|
||||
|
||||
String opts = format("-D DEPTH_%d -D OP_MIN_MAX_LOC%s -D WGS=%d -D WGS2_ALIGNED=%d%s",
|
||||
depth, _mask.empty() ? "" : "_MASK", (int)wgs, wgs2_aligned, doubleSupport ? " -D DOUBLE_SUPPORT" : "");
|
||||
String opts = format("-D DEPTH_%d -D srcT=%s -D OP_MIN_MAX_LOC%s -D WGS=%d -D WGS2_ALIGNED=%d%s",
|
||||
depth, ocl::typeToStr(depth), _mask.empty() ? "" : "_MASK", (int)wgs,
|
||||
wgs2_aligned, doubleSupport ? " -D DOUBLE_SUPPORT" : "");
|
||||
|
||||
ocl::Kernel k("reduce", ocl::core::reduce_oclsrc, opts);
|
||||
if (k.empty())
|
||||
@ -1980,12 +1982,14 @@ static bool ocl_norm( InputArray _src, int normType, InputArray _mask, double &
|
||||
haveMask = _mask.kind() != _InputArray::NONE;
|
||||
|
||||
if ( !(normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR) ||
|
||||
(!doubleSupport && depth == CV_64F) || (normType == NORM_INF && haveMask && cn != 1))
|
||||
(!doubleSupport && depth == CV_64F))
|
||||
return false;
|
||||
|
||||
UMat src = _src.getUMat();
|
||||
|
||||
if (normType == NORM_INF)
|
||||
{
|
||||
if (cn == 1 || !haveMask)
|
||||
{
|
||||
UMat abssrc;
|
||||
|
||||
@ -2014,6 +2018,35 @@ static bool ocl_norm( InputArray _src, int normType, InputArray _mask, double &
|
||||
|
||||
cv::minMaxIdx(haveMask ? abssrc : abssrc.reshape(1), NULL, &result, NULL, NULL, _mask);
|
||||
}
|
||||
else
|
||||
{
|
||||
int dbsize = ocl::Device::getDefault().maxComputeUnits();
|
||||
size_t wgs = ocl::Device::getDefault().maxWorkGroupSize();
|
||||
|
||||
int wgs2_aligned = 1;
|
||||
while (wgs2_aligned < (int)wgs)
|
||||
wgs2_aligned <<= 1;
|
||||
wgs2_aligned >>= 1;
|
||||
|
||||
ocl::Kernel k("reduce", ocl::core::reduce_oclsrc,
|
||||
format("-D OP_NORM_INF_MASK -D HAVE_MASK -D DEPTH_%d"
|
||||
" -D srcT=%s -D srcT1=%s -D WGS=%d -D cn=%d -D WGS2_ALIGNED=%d%s",
|
||||
depth, ocl::typeToStr(type), ocl::typeToStr(depth),
|
||||
wgs, cn, wgs2_aligned, doubleSupport ? " -D DOUBLE_SUPPORT" : ""));
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
UMat db(1, dbsize, type), mask = _mask.getUMat();
|
||||
k.args(ocl::KernelArg::ReadOnlyNoSize(src), src.cols, (int)src.total(),
|
||||
dbsize, ocl::KernelArg::PtrWriteOnly(db), ocl::KernelArg::ReadOnlyNoSize(mask));
|
||||
|
||||
size_t globalsize = dbsize * wgs;
|
||||
if (!k.run(1, &globalsize, &wgs, true))
|
||||
return false;
|
||||
|
||||
minMaxIdx(db.getMat(ACCESS_READ), NULL, &result, NULL, NULL, noArray());
|
||||
}
|
||||
}
|
||||
else if (normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR)
|
||||
{
|
||||
Scalar sc;
|
||||
|
@ -1149,7 +1149,7 @@ OCL_TEST_P(MinMaxIdx, Mat)
|
||||
int p1[2], p2[2], up1[2], up2[2];
|
||||
double minv, maxv, uminv, umaxv;
|
||||
|
||||
if(src1_roi.channels() > 1)
|
||||
if (cn > 1)
|
||||
{
|
||||
OCL_OFF(cv::minMaxIdx(src2_roi, &minv, &maxv) );
|
||||
OCL_ON(cv::minMaxIdx(usrc2_roi, &uminv, &umaxv));
|
||||
@ -1164,6 +1164,7 @@ OCL_TEST_P(MinMaxIdx, Mat)
|
||||
|
||||
EXPECT_DOUBLE_EQ(minv, uminv);
|
||||
EXPECT_DOUBLE_EQ(maxv, umaxv);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
EXPECT_EQ(p1[i], up1[i]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user