diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 024f611ffb..086041239b 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -3157,10 +3157,9 @@ static bool ocl_filter2D( InputArray _src, OutputArray _dst, int ddepth, if (abs(delta) > FLT_MIN) return false; - int type = _src.type(); - int cn = CV_MAT_CN(type); - if ((1 != cn) && (2 != cn) && (4 != cn)) - return false;//TODO + int type = _src.type(), cn = CV_MAT_CN(type); + if (cn > 4) + return false; int sdepth = CV_MAT_DEPTH(type); Size ksize = _kernel.size(); @@ -3298,7 +3297,7 @@ static bool ocl_filter2D( InputArray _src, OutputArray _dst, int ddepth, double borderValueDouble[4] = {0, 0, 0, 0}; if ((borderType & ~BORDER_ISOLATED) == BORDER_CONSTANT) { - int cnocl = (3 == cn) ? 4 : cn; + int cnocl = 3 == cn ? 4 : cn; if (useDouble) idxArg = kernel.set(idxArg, (void *)&borderValueDouble[0], sizeof(double) * cnocl); else diff --git a/modules/imgproc/src/opencl/filter2D.cl b/modules/imgproc/src/opencl/filter2D.cl index d360714971..4c7d789bc5 100644 --- a/modules/imgproc/src/opencl/filter2D.cl +++ b/modules/imgproc/src/opencl/filter2D.cl @@ -203,10 +203,24 @@ #define VEC_TYPE CAT(BASE_TYPE, VEC_SIZE) #define TYPE VEC_TYPE +#if VEC_SIZE == 3 +#define SCALAR_TYPE CAT(FPTYPE, 4) +#else #define SCALAR_TYPE CAT(FPTYPE, VEC_SIZE) +#endif #define INTERMEDIATE_TYPE CAT(FPTYPE, VEC_SIZE) +#if DATA_CHAN != 3 +#define loadpix(addr) *(__global const TYPE *)(addr) +#define storepix(val, addr) *(__global TYPE *)(addr) = val +#define TSIZE (int)sizeof(TYPE) +#else +#define loadpix(addr) vload3(0, (__global const BASE_TYPE *)(addr)) +#define storepix(val, addr) vstore3(val, 0, (__global BASE_TYPE *)(addr)) +#define TSIZE (int)sizeof(BASE_TYPE)*DATA_CHAN +#endif + struct RectCoords { int x1, y1, x2, y2; @@ -235,13 +249,17 @@ inline INTERMEDIATE_TYPE readSrcPixel(int2 pos, __global const uchar* srcptr, in #endif { //__global TYPE* ptr = (__global TYPE*)((__global char*)src + pos.x * sizeof(TYPE) + pos.y * srcStepBytes); - __global TYPE* ptr = (__global TYPE*)(srcptr + pos.y * srcstep + pos.x * sizeof(TYPE)); - return CONVERT_TO_FPTYPE(*ptr); + __global TYPE* ptr = (__global TYPE*)(srcptr + pos.y * srcstep + pos.x * TSIZE); + return CONVERT_TO_FPTYPE(loadpix(ptr)); } else { #ifdef BORDER_CONSTANT +#if VEC_SIZE == 3 + return (INTERMEDIATE_TYPE)(borderValue.x, borderValue.y, borderValue.z); +#else return borderValue; +#endif #else int selected_col = pos.x; int selected_row = pos.y; @@ -262,8 +280,8 @@ inline INTERMEDIATE_TYPE readSrcPixel(int2 pos, __global const uchar* srcptr, in if(pos.x >= 0 && pos.y >= 0 && pos.x < srcCoords.x2 && pos.y < srcCoords.y2) { //__global TYPE* ptr = (__global TYPE*)((__global char*)src + pos.x * sizeof(TYPE) + pos.y * srcStepBytes); - __global TYPE* ptr = (__global TYPE*)(srcptr + pos.y * srcstep + pos.x * sizeof(TYPE)); - return CONVERT_TO_FPTYPE(*ptr); + __global TYPE* ptr = (__global TYPE*)(srcptr + pos.y * srcstep + pos.x * TSIZE); + return CONVERT_TO_FPTYPE(loadpix(ptr)); } else { @@ -300,7 +318,7 @@ void filter2D(__global const uchar* srcptr, int srcstep, int srcOffsetX, int src int2 srcPos = (int2)(srcCoords.x1 + x, srcCoords.y1 + y - ANCHOR_Y); int2 pos = (int2)(x, y); - __global TYPE* dstPtr = (__global TYPE*)((__global char*)dstptr + pos.y * dststep + dstoffset + pos.x * sizeof(TYPE)); // Pointer can be out of bounds! + __global TYPE* dstPtr = (__global TYPE*)((__global char*)dstptr + pos.y * dststep + dstoffset + pos.x * TSIZE); // Pointer can be out of bounds! bool writeResult = ((local_id >= ANCHOR_X) && (local_id < LOCAL_SIZE - (KERNEL_SIZE_X - 1 - ANCHOR_X)) && (pos.x >= 0) && (pos.x < cols)); @@ -360,7 +378,7 @@ void filter2D(__global const uchar* srcptr, int srcstep, int srcOffsetX, int src if (writeResult) { - *dstPtr = CONVERT_TO_TYPE(total_sum); + storepix(CONVERT_TO_TYPE(total_sum), dstPtr); } #if BLOCK_SIZE_Y > 1 diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 0a657f4dd1..b7a5d81e5d 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -41,7 +41,6 @@ //M*/ #include "precomp.hpp" -#define CV_OPENCL_RUN_ASSERT #include "opencl_kernels.hpp" /* @@ -642,10 +641,7 @@ static bool ocl_boxFilter( InputArray _src, OutputArray _dst, int ddepth, if (cn > 4 || (!doubleSupport && (sdepth == CV_64F || ddepth == CV_64F)) || _src.offset() % esz != 0 || _src.step() % esz != 0) - { - printf("!!!!!!!!!!!!!!!!!!!!!!!\n"); return false; - } if (anchor.x < 0) anchor.x = ksize.width / 2; diff --git a/modules/imgproc/test/ocl/test_filter2d.cpp b/modules/imgproc/test/ocl/test_filter2d.cpp index 21b3fff2d7..f1f89a113b 100644 --- a/modules/imgproc/test/ocl/test_filter2d.cpp +++ b/modules/imgproc/test/ocl/test_filter2d.cpp @@ -115,11 +115,10 @@ OCL_TEST_P(Filter2D, Mat) } } - OCL_INSTANTIATE_TEST_CASE_P(ImageProc, Filter2D, Combine( - Values(CV_8U, CV_16U, CV_16S, CV_32F, CV_64F), - Values(1, 2, 4), + Values(CV_8U, CV_16U, CV_32F), + OCL_ALL_CHANNELS, Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE, (BorderType)BORDER_REFLECT, diff --git a/modules/imgproc/test/ocl/test_filters.cpp b/modules/imgproc/test/ocl/test_filters.cpp index d2819a388c..46fb4d6b75 100644 --- a/modules/imgproc/test/ocl/test_filters.cpp +++ b/modules/imgproc/test/ocl/test_filters.cpp @@ -304,7 +304,7 @@ OCL_TEST_P(MorphologyEx, Mat) (int)BORDER_REFLECT|BORDER_ISOLATED, (int)BORDER_WRAP|BORDER_ISOLATED, \ (int)BORDER_REFLECT_101|BORDER_ISOLATED*/) // WRAP and ISOLATED are not supported by cv:: version -#define FILTER_TYPES Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4) +#define FILTER_TYPES Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4) OCL_INSTANTIATE_TEST_CASE_P(Filter, Bilateral, Combine( Values(CV_8UC1, CV_8UC3),