diff --git a/modules/cudaarithm/src/cuda/absdiff_mat.cu b/modules/cudaarithm/src/cuda/absdiff_mat.cu index ec04f12284..da475563e2 100644 --- a/modules/cudaarithm/src/cuda/absdiff_mat.cu +++ b/modules/cudaarithm/src/cuda/absdiff_mat.cu @@ -135,7 +135,7 @@ namespace void absDiffMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int) { typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream); - static const func_t funcs[] = + static const func_t funcs[CV_DEPTH_MAX] = { absDiffMat_v1, absDiffMat_v1, diff --git a/modules/cudaarithm/src/cuda/absdiff_scalar.cu b/modules/cudaarithm/src/cuda/absdiff_scalar.cu index 2a559daaed..34d3fa8873 100644 --- a/modules/cudaarithm/src/cuda/absdiff_scalar.cu +++ b/modules/cudaarithm/src/cuda/absdiff_scalar.cu @@ -95,7 +95,7 @@ namespace void absDiffScalar(const GpuMat& src, cv::Scalar val, bool, GpuMat& dst, const GpuMat&, double, Stream& stream, int) { typedef void (*func_t)(const GpuMat& src, cv::Scalar val, GpuMat& dst, Stream& stream); - static const func_t funcs[7][4] = + static const func_t funcs[CV_DEPTH_MAX][4] = { { absDiffScalarImpl, absDiffScalarImpl, absDiffScalarImpl, absDiffScalarImpl diff --git a/modules/cudaarithm/src/cuda/cmp_scalar.cu b/modules/cudaarithm/src/cuda/cmp_scalar.cu index df57bc0043..01a8696de1 100644 --- a/modules/cudaarithm/src/cuda/cmp_scalar.cu +++ b/modules/cudaarithm/src/cuda/cmp_scalar.cu @@ -217,7 +217,7 @@ void cmpScalar(const GpuMat& src, cv::Scalar val, bool inv, GpuMat& dst, const G const int depth = src.depth(); const int cn = src.channels(); - CV_DbgAssert( depth <= CV_64F && cn <= 4 ); + CV_Assert( depth <= CV_64F && cn <= 4 ); funcs[depth][cmpop][cn - 1](src, val, dst, stream); } diff --git a/modules/cudaarithm/src/cuda/div_mat.cu b/modules/cudaarithm/src/cuda/div_mat.cu index 2a2fb9bf51..1f582b1782 100644 --- a/modules/cudaarithm/src/cuda/div_mat.cu +++ b/modules/cudaarithm/src/cuda/div_mat.cu @@ -120,7 +120,7 @@ namespace void divMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& stream, int) { typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, const GpuMat& dst, double scale, Stream& stream); - static const func_t funcs[7][7] = + static const func_t funcs[CV_DEPTH_MAX][CV_DEPTH_MAX] = { { divMatImpl, @@ -190,8 +190,6 @@ void divMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, const int sdepth = src1.depth(); const int ddepth = dst.depth(); - CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F ); - GpuMat src1_ = src1.reshape(1); GpuMat src2_ = src2.reshape(1); GpuMat dst_ = dst.reshape(1); diff --git a/modules/cudaarithm/src/cuda/minmax.cu b/modules/cudaarithm/src/cuda/minmax.cu index c5e912c8e9..ecfef6bab8 100644 --- a/modules/cudaarithm/src/cuda/minmax.cu +++ b/modules/cudaarithm/src/cuda/minmax.cu @@ -87,7 +87,7 @@ namespace void cv::cuda::findMinMax(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream) { typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream); - static const func_t funcs[] = + static const func_t funcs[CV_DEPTH_MAX] = { minMaxImpl, minMaxImpl, @@ -110,6 +110,8 @@ void cv::cuda::findMinMax(InputArray _src, OutputArray _dst, InputArray _mask, S GpuMat dst = getOutputMat(_dst, 1, 2, dst_depth, stream); const func_t func = funcs[src.depth()]; + CV_Assert(func); + func(src, mask, dst, stream); syncOutput(dst, _dst, stream); @@ -158,7 +160,7 @@ namespace void cv::cuda::device::findMaxAbs(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream) { typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream); - static const func_t funcs[] = + static const func_t funcs[CV_DEPTH_MAX] = { findMaxAbsImpl, findMaxAbsImpl, @@ -181,6 +183,8 @@ void cv::cuda::device::findMaxAbs(InputArray _src, OutputArray _dst, InputArray GpuMat dst = getOutputMat(_dst, 1, 1, dst_depth, stream); const func_t func = funcs[src.depth()]; + CV_Assert(func); + func(src, mask, dst, stream); syncOutput(dst, _dst, stream); diff --git a/modules/cudaarithm/src/cuda/minmax_mat.cu b/modules/cudaarithm/src/cuda/minmax_mat.cu index 405b230868..9c2114b0c8 100644 --- a/modules/cudaarithm/src/cuda/minmax_mat.cu +++ b/modules/cudaarithm/src/cuda/minmax_mat.cu @@ -127,7 +127,7 @@ namespace void minMaxMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double, Stream& stream, int op) { typedef void (*func_t)(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream); - static const func_t funcs_v1[2][7] = + static const func_t funcs_v1[2][CV_DEPTH_MAX] = { { minMaxMat_v1, @@ -161,8 +161,6 @@ void minMaxMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat const int depth = src1.depth(); - CV_DbgAssert( depth <= CV_64F ); - GpuMat src1_ = src1.reshape(1); GpuMat src2_ = src2.reshape(1); GpuMat dst_ = dst.reshape(1); @@ -191,6 +189,7 @@ void minMaxMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat } const func_t func = funcs_v1[op][depth]; + CV_Assert(func); func(src1_, src2_, dst_, stream); } @@ -209,8 +208,10 @@ namespace void minMaxScalar(const GpuMat& src, cv::Scalar value, bool, GpuMat& dst, const GpuMat&, double, Stream& stream, int op) { + CV_DbgAssert( src.channels() == 1 ); + typedef void (*func_t)(const GpuMat& src, double value, GpuMat& dst, Stream& stream); - static const func_t funcs[2][7] = + static const func_t funcs[2][CV_DEPTH_MAX] = { { minMaxScalar, @@ -232,12 +233,10 @@ void minMaxScalar(const GpuMat& src, cv::Scalar value, bool, GpuMat& dst, const } }; - const int depth = src.depth(); - - CV_DbgAssert( depth <= CV_64F ); - CV_DbgAssert( src.channels() == 1 ); + auto f = funcs[op][src.depth()]; + CV_Assert(f); - funcs[op][depth](src, value[0], dst, stream); + f(src, value[0], dst, stream); } #endif diff --git a/modules/cudaarithm/src/cuda/minmaxloc.cu b/modules/cudaarithm/src/cuda/minmaxloc.cu index b7c5ec872f..568fe2a12e 100644 --- a/modules/cudaarithm/src/cuda/minmaxloc.cu +++ b/modules/cudaarithm/src/cuda/minmaxloc.cu @@ -75,7 +75,7 @@ namespace void cv::cuda::findMinMaxLoc(InputArray _src, OutputArray _minMaxVals, OutputArray _loc, InputArray _mask, Stream& stream) { typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _valBuf, GpuMat& _locBuf, Stream& stream); - static const func_t funcs[] = + static const func_t funcs[CV_DEPTH_MAX] = { minMaxLocImpl, minMaxLocImpl, @@ -99,6 +99,7 @@ void cv::cuda::findMinMaxLoc(InputArray _src, OutputArray _minMaxVals, OutputArr GpuMat locBuf(pool.getAllocator()); const func_t func = funcs[src_depth]; + CV_Assert(func); func(src, mask, valBuf, locBuf, stream); GpuMat minMaxVals = valBuf.colRange(0, 1); diff --git a/modules/cudaarithm/src/cuda/norm.cu b/modules/cudaarithm/src/cuda/norm.cu index 43bd358f32..062de531a3 100644 --- a/modules/cudaarithm/src/cuda/norm.cu +++ b/modules/cudaarithm/src/cuda/norm.cu @@ -161,7 +161,7 @@ namespace void cv::cuda::device::normL2(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream) { typedef void (*func_t)(const GpuMat& _src, const GpuMat& mask, GpuMat& _dst, Stream& stream); - static const func_t funcs[] = + static const func_t funcs[CV_DEPTH_MAX] = { normL2Impl, normL2Impl, @@ -181,6 +181,7 @@ void cv::cuda::device::normL2(InputArray _src, OutputArray _dst, InputArray _mas GpuMat dst = getOutputMat(_dst, 1, 1, CV_64FC1, stream); const func_t func = funcs[src.depth()]; + CV_Assert(func); func(src, mask, dst, stream); syncOutput(dst, _dst, stream); diff --git a/modules/cudaarithm/src/cuda/normalize.cu b/modules/cudaarithm/src/cuda/normalize.cu index c83f2c0dff..ed529deaa4 100644 --- a/modules/cudaarithm/src/cuda/normalize.cu +++ b/modules/cudaarithm/src/cuda/normalize.cu @@ -219,7 +219,7 @@ void cv::cuda::normalize(InputArray _src, OutputArray _dst, double a, double b, typedef void (*func_minmax_t)(const GpuMat& _src, GpuMat& _dst, double a, double b, const GpuMat& mask, Stream& stream); typedef void (*func_norm_t)(const GpuMat& _src, GpuMat& _dst, double a, int normType, const GpuMat& mask, Stream& stream); - static const func_minmax_t funcs_minmax[] = + static const func_minmax_t funcs_minmax[CV_DEPTH_MAX] = { normalizeMinMax, normalizeMinMax, @@ -230,7 +230,7 @@ void cv::cuda::normalize(InputArray _src, OutputArray _dst, double a, double b, normalizeMinMax }; - static const func_norm_t funcs_norm[] = + static const func_norm_t funcs_norm[CV_DEPTH_MAX] = { normalizeNorm, normalizeNorm, @@ -273,11 +273,13 @@ void cv::cuda::normalize(InputArray _src, OutputArray _dst, double a, double b, if (normType == NORM_MINMAX) { const func_minmax_t func = funcs_minmax[src_depth]; + CV_Assert(func); func(src, dst, a, b, mask, stream); } else { const func_norm_t func = funcs_norm[src_depth]; + CV_Assert(func); func(src, dst, a, normType, mask, stream); } diff --git a/modules/cudaarithm/src/cuda/reduce.cu b/modules/cudaarithm/src/cuda/reduce.cu index 3f907c7955..82e1e639aa 100644 --- a/modules/cudaarithm/src/cuda/reduce.cu +++ b/modules/cudaarithm/src/cuda/reduce.cu @@ -142,7 +142,7 @@ void cv::cuda::reduce(InputArray _src, OutputArray _dst, int dim, int reduceOp, if (dim == 0) { typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream); - static const func_t funcs[7][7] = + static const func_t funcs[CV_DEPTH_MAX][CV_DEPTH_MAX] = { { reduceToRowImpl, @@ -220,7 +220,7 @@ void cv::cuda::reduce(InputArray _src, OutputArray _dst, int dim, int reduceOp, else { typedef void (*func_t)(const GpuMat& _src, GpuMat& _dst, int reduceOp, Stream& stream); - static const func_t funcs[7][7] = + static const func_t funcs[CV_DEPTH_MAX][CV_DEPTH_MAX] = { { reduceToColumnImpl, diff --git a/modules/cudaarithm/src/cuda/sub_mat.cu b/modules/cudaarithm/src/cuda/sub_mat.cu index 6468692aee..3595988ee2 100644 --- a/modules/cudaarithm/src/cuda/sub_mat.cu +++ b/modules/cudaarithm/src/cuda/sub_mat.cu @@ -185,7 +185,7 @@ void subMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& m const int sdepth = src1.depth(); const int ddepth = dst.depth(); - CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F ); + CV_Assert( sdepth <= CV_64F && ddepth <= CV_64F ); GpuMat src1_ = src1.reshape(1); GpuMat src2_ = src2.reshape(1); diff --git a/modules/cudaarithm/src/cuda/threshold.cu b/modules/cudaarithm/src/cuda/threshold.cu index 5c60161af9..02cdc6ed2d 100644 --- a/modules/cudaarithm/src/cuda/threshold.cu +++ b/modules/cudaarithm/src/cuda/threshold.cu @@ -374,7 +374,7 @@ double cv::cuda::threshold(InputArray _src, OutputArray _dst, double thresh, dou else { typedef void (*func_t)(const GpuMat& src, GpuMat& dst, double thresh, double maxVal, int type, Stream& stream); - static const func_t funcs[] = + static const func_t funcs[CV_DEPTH_MAX] = { thresholdImpl, thresholdImpl, @@ -391,7 +391,10 @@ double cv::cuda::threshold(InputArray _src, OutputArray _dst, double thresh, dou maxVal = cvRound(maxVal); } - funcs[depth](src, dst, thresh, maxVal, type, stream); + auto f = funcs[depth]; + CV_Assert(f); + + f(src, dst, thresh, maxVal, type, stream); } syncOutput(dst, _dst, stream); diff --git a/modules/cudaarithm/test/test_element_operations.cpp b/modules/cudaarithm/test/test_element_operations.cpp index f4628ad7f1..46e156d993 100644 --- a/modules/cudaarithm/test/test_element_operations.cpp +++ b/modules/cudaarithm/test/test_element_operations.cpp @@ -1570,13 +1570,16 @@ namespace { typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst); - const func_t funcs[] = + const func_t funcs[CV_DEPTH_MAX] = { sqrtImpl, sqrtImpl, sqrtImpl, sqrtImpl, sqrtImpl, sqrtImpl }; - funcs[src.depth()](src, dst); + auto f = funcs[src.depth()]; + CV_Assert(f); + + f(src, dst); } } @@ -1640,13 +1643,16 @@ namespace { typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst); - const func_t funcs[] = + const func_t funcs[CV_DEPTH_MAX] = { logImpl, logImpl, logImpl, logImpl, logImpl, logImpl }; - funcs[src.depth()](src, dst); + auto f = funcs[src.depth()]; + CV_Assert(f); + + f(src, dst); } } @@ -1720,13 +1726,16 @@ namespace { typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst); - const func_t funcs[] = + const func_t funcs[CV_DEPTH_MAX] = { expImpl, expImpl, expImpl, expImpl, expImpl, expImpl_float }; - funcs[src.depth()](src, dst); + auto f = funcs[src.depth()]; + CV_Assert(f); + + f(src, dst); } } @@ -1921,8 +1930,10 @@ namespace void compareScalarGold(const cv::Mat& src, cv::Scalar sc, cv::Mat& dst, int cmpop) { + CV_Assert(cmpop < 6); + typedef void (*func_t)(const cv::Mat& src, cv::Scalar sc, cv::Mat& dst); - static const func_t funcs[7][6] = + static const func_t funcs[CV_DEPTH_MAX][6] = { {compareScalarImpl , compareScalarImpl , compareScalarImpl , compareScalarImpl , compareScalarImpl , compareScalarImpl }, {compareScalarImpl , compareScalarImpl , compareScalarImpl , compareScalarImpl , compareScalarImpl , compareScalarImpl }, @@ -1933,7 +1944,10 @@ namespace {compareScalarImpl , compareScalarImpl , compareScalarImpl , compareScalarImpl , compareScalarImpl , compareScalarImpl } }; - funcs[src.depth()][cmpop](src, sc, dst); + auto f = funcs[src.depth()][cmpop]; + CV_Assert(f); + + f(src, sc, dst); } } @@ -2164,12 +2178,14 @@ namespace { typedef void (*func_t)(const cv::Mat& src, cv::Scalar_ val, cv::Mat& dst); - const func_t funcs[] = + const func_t funcs[CV_DEPTH_MAX] = { rhiftImpl, rhiftImpl, rhiftImpl, rhiftImpl, rhiftImpl }; - funcs[src.depth()](src, val, dst); + auto f = funcs[src.depth()]; + CV_Assert(f); + f(src, val, dst); } } @@ -2244,12 +2260,15 @@ namespace { typedef void (*func_t)(const cv::Mat& src, cv::Scalar_ val, cv::Mat& dst); - const func_t funcs[] = + const func_t funcs[CV_DEPTH_MAX] = { lhiftImpl, lhiftImpl, lhiftImpl, lhiftImpl, lhiftImpl }; - funcs[src.depth()](src, val, dst); + auto f = funcs[src.depth()]; + CV_Assert(f); + + f(src, val, dst); } } diff --git a/modules/cudaarithm/test/test_reductions.cpp b/modules/cudaarithm/test/test_reductions.cpp index 5ec6274523..fab5b7ca56 100644 --- a/modules/cudaarithm/test/test_reductions.cpp +++ b/modules/cudaarithm/test/test_reductions.cpp @@ -201,7 +201,7 @@ namespace { typedef cv::Scalar (*func_t)(const cv::Mat& src); - static const func_t funcs[] = + static const func_t funcs[CV_DEPTH_MAX] = { absSumImpl, absSumImpl, @@ -212,7 +212,10 @@ namespace absSumImpl }; - return funcs[src.depth()](src); + auto f = funcs[src.depth()]; + CV_Assert(f); + + return f(src); } template @@ -241,7 +244,7 @@ namespace { typedef cv::Scalar (*func_t)(const cv::Mat& src); - static const func_t funcs[] = + static const func_t funcs[CV_DEPTH_MAX] = { sqrSumImpl, sqrSumImpl, @@ -252,7 +255,10 @@ namespace sqrSumImpl }; - return funcs[src.depth()](src); + auto f = funcs[src.depth()]; + CV_Assert(f); + + return f(src); } } @@ -519,7 +525,7 @@ namespace { typedef void (*func_t)(const cv::Mat& src, cv::Point loc_gold, cv::Point loc); - static const func_t funcs[] = + static const func_t funcs[CV_DEPTH_MAX] = { expectEqualImpl, expectEqualImpl, @@ -530,7 +536,10 @@ namespace expectEqualImpl }; - funcs[src.depth()](src, loc_gold, loc); + auto f = funcs[src.depth()]; + CV_Assert(f); + + f(src, loc_gold, loc); } }