From f218dffce6b9d0cf70ec5905896c3b2f008e826e Mon Sep 17 00:00:00 2001 From: Alexander Karsakov Date: Wed, 16 Apr 2014 11:39:10 +0400 Subject: [PATCH 1/7] Added ippiPyrDown_Gauss5x5 to cv::pyrDown --- modules/imgproc/src/pyramids.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index f898c8f7de..e6ce7bc234 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -501,13 +501,43 @@ void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borde Size dsz = _dsz.area() == 0 ? Size((src.cols + 1)/2, (src.rows + 1)/2) : _dsz; _dst.create( dsz, src.type() ); Mat dst = _dst.getMat(); + int depth = src.depth(); #ifdef HAVE_TEGRA_OPTIMIZATION if(borderType == BORDER_DEFAULT && tegra::pyrDown(src, dst)) return; #endif - int depth = src.depth(); +#if (defined(HAVE_IPP) && !defined(HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 801) + typedef IppStatus (CV_STDCALL * ippiPyrDown)(const void* pSrc, int srcStep, void* pDst, int dstStep, IppiSize srcRoi, Ipp8u* buffer); + int type = src.type(); + CV_SUPPRESS_DEPRECATED_START + ippiPyrDown pyrDownFunc = type == CV_8UC1 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_8u_C1R : + type == CV_8UC3 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_8u_C3R : + type == CV_32FC1 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_32f_C1R : + type == CV_32FC3 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_32f_C3R : 0; + CV_SUPPRESS_DEPRECATED_END + + if (pyrDownFunc) + { + int bufferSize; + IppiSize srcRoi = { src.cols, src.rows }; + IppDataType dataType = depth == CV_8U ? ipp8u : ipp32f; + CV_SUPPRESS_DEPRECATED_START + IppStatus ok = ippiPyrDownGetBufSize_Gauss5x5(srcRoi.width, dataType, src.channels(), &bufferSize); + CV_SUPPRESS_DEPRECATED_END + if (ok >= 0) + { + Ipp8u* buffer = ippsMalloc_8u(bufferSize); + ok = pyrDownFunc(src.data, (int) src.step, dst.data, (int) dst.step, srcRoi, buffer); + ippsFree(buffer); + + if (ok >= 0) + return; + } + } +#endif + PyrFunc func = 0; if( depth == CV_8U ) func = pyrDown_, PyrDownVec_32s8u>; From 8230f1fd68421410bb0bc399db855effa6245204 Mon Sep 17 00:00:00 2001 From: Alexander Karsakov Date: Wed, 16 Apr 2014 11:59:32 +0400 Subject: [PATCH 2/7] Added ippiPyrUp_Gauss5x5 to cv::pyrUp --- modules/imgproc/src/pyramids.cpp | 82 ++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 21 deletions(-) diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index e6ce7bc234..3f51908348 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -509,31 +509,36 @@ void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borde #endif #if (defined(HAVE_IPP) && !defined(HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 801) - typedef IppStatus (CV_STDCALL * ippiPyrDown)(const void* pSrc, int srcStep, void* pDst, int dstStep, IppiSize srcRoi, Ipp8u* buffer); - int type = src.type(); - CV_SUPPRESS_DEPRECATED_START - ippiPyrDown pyrDownFunc = type == CV_8UC1 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_8u_C1R : - type == CV_8UC3 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_8u_C3R : - type == CV_32FC1 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_32f_C1R : - type == CV_32FC3 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_32f_C3R : 0; - CV_SUPPRESS_DEPRECATED_END - - if (pyrDownFunc) + bool isolated = (borderType & BORDER_ISOLATED) != 0; + int borderTypeNI = borderType & ~BORDER_ISOLATED; + if (borderTypeNI == BORDER_DEFAULT && (!src.isSubmatrix() || isolated)) { - int bufferSize; - IppiSize srcRoi = { src.cols, src.rows }; - IppDataType dataType = depth == CV_8U ? ipp8u : ipp32f; + typedef IppStatus (CV_STDCALL * ippiPyrDown)(const void* pSrc, int srcStep, void* pDst, int dstStep, IppiSize srcRoi, Ipp8u* buffer); + int type = src.type(); CV_SUPPRESS_DEPRECATED_START - IppStatus ok = ippiPyrDownGetBufSize_Gauss5x5(srcRoi.width, dataType, src.channels(), &bufferSize); + ippiPyrDown pyrDownFunc = type == CV_8UC1 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_8u_C1R : + type == CV_8UC3 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_8u_C3R : + type == CV_32FC1 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_32f_C1R : + type == CV_32FC3 ? (ippiPyrDown) ippiPyrDown_Gauss5x5_32f_C3R : 0; CV_SUPPRESS_DEPRECATED_END - if (ok >= 0) - { - Ipp8u* buffer = ippsMalloc_8u(bufferSize); - ok = pyrDownFunc(src.data, (int) src.step, dst.data, (int) dst.step, srcRoi, buffer); - ippsFree(buffer); + if (pyrDownFunc) + { + int bufferSize; + IppiSize srcRoi = { src.cols, src.rows }; + IppDataType dataType = depth == CV_8U ? ipp8u : ipp32f; + CV_SUPPRESS_DEPRECATED_START + IppStatus ok = ippiPyrDownGetBufSize_Gauss5x5(srcRoi.width, dataType, src.channels(), &bufferSize); + CV_SUPPRESS_DEPRECATED_END if (ok >= 0) - return; + { + Ipp8u* buffer = ippsMalloc_8u(bufferSize); + ok = pyrDownFunc(src.data, (int) src.step, dst.data, (int) dst.step, srcRoi, buffer); + ippsFree(buffer); + + if (ok >= 0) + return; + } } } #endif @@ -564,13 +569,48 @@ void cv::pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int borderT Size dsz = _dsz.area() == 0 ? Size(src.cols*2, src.rows*2) : _dsz; _dst.create( dsz, src.type() ); Mat dst = _dst.getMat(); + int depth = src.depth(); #ifdef HAVE_TEGRA_OPTIMIZATION if(borderType == BORDER_DEFAULT && tegra::pyrUp(src, dst)) return; #endif - int depth = src.depth(); +#if (defined(HAVE_IPP) && !defined(HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 801) + bool isolated = (borderType & BORDER_ISOLATED) != 0; + int borderTypeNI = borderType & ~BORDER_ISOLATED; + if (borderTypeNI == BORDER_DEFAULT && (!src.isSubmatrix() || isolated)) + { + typedef IppStatus (CV_STDCALL * ippiPyrUp)(const void* pSrc, int srcStep, void* pDst, int dstStep, IppiSize srcRoi, Ipp8u* buffer); + int type = src.type(); + CV_SUPPRESS_DEPRECATED_START + ippiPyrUp pyrUpFunc = type == CV_8UC1 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_8u_C1R : + type == CV_8UC3 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_8u_C3R : + type == CV_32FC1 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_32f_C1R : + type == CV_32FC3 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_32f_C3R : 0; + CV_SUPPRESS_DEPRECATED_END + + if (pyrUpFunc) + { + int bufferSize; + IppiSize srcRoi = { src.cols, src.rows }; + IppDataType dataType = depth == CV_8U ? ipp8u : ipp32f; + CV_SUPPRESS_DEPRECATED_START + IppStatus ok = ippiPyrUpGetBufSize_Gauss5x5(srcRoi.width, dataType, src.channels(), &bufferSize); + CV_SUPPRESS_DEPRECATED_END + if (ok >= 0) + { + Ipp8u* buffer = ippsMalloc_8u(bufferSize); + ok = pyrUpFunc(src.data, (int) src.step, dst.data, (int) dst.step, srcRoi, buffer); + ippsFree(buffer); + + if (ok >= 0) + return; + } + } + } +#endif + PyrFunc func = 0; if( depth == CV_8U ) func = pyrUp_, NoVec >; From ef2f5999ed0666d9b8c06fa02f2a511ed0fad4ce Mon Sep 17 00:00:00 2001 From: Alexander Karsakov Date: Wed, 16 Apr 2014 13:01:49 +0400 Subject: [PATCH 3/7] Added perf test for cv::buildPyramid --- modules/imgproc/perf/perf_pyramids.cpp | 31 ++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/modules/imgproc/perf/perf_pyramids.cpp b/modules/imgproc/perf/perf_pyramids.cpp index 66ea6d80fb..1310239bf1 100644 --- a/modules/imgproc/perf/perf_pyramids.cpp +++ b/modules/imgproc/perf/perf_pyramids.cpp @@ -8,7 +8,7 @@ using std::tr1::get; PERF_TEST_P(Size_MatType, pyrDown, testing::Combine( testing::Values(sz1080p, sz720p, szVGA, szQVGA, szODD), - testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16SC1, CV_16SC3, CV_16SC4) + testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16SC1, CV_16SC3, CV_16SC4, CV_32FC1, CV_32FC3, CV_32FC4) ) ) { @@ -27,7 +27,7 @@ PERF_TEST_P(Size_MatType, pyrDown, testing::Combine( PERF_TEST_P(Size_MatType, pyrUp, testing::Combine( testing::Values(sz720p, szVGA, szQVGA, szODD), - testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16SC1, CV_16SC3, CV_16SC4) + testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16SC1, CV_16SC3, CV_16SC4, CV_32FC1, CV_32FC3, CV_32FC4) ) ) { @@ -43,3 +43,30 @@ PERF_TEST_P(Size_MatType, pyrUp, testing::Combine( SANITY_CHECK(dst); } + +PERF_TEST_P(Size_MatType, buildPyramid, testing::Combine( + testing::Values(sz2160p, sz1080p, sz720p, szVGA, szQVGA, szODD), + testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4) + ) + ) +{ + Size sz = get<0>(GetParam()); + int matType = get<1>(GetParam()); + int maxLevel = 5; + const double eps = CV_MAT_DEPTH(matType) <= CV_32S ? 1 : 1e-5; + + Mat src(sz, matType); + std::vector dst(maxLevel); + + declare.in(src, WARMUP_RNG); + + TEST_CYCLE() buildPyramid(src, dst, maxLevel); + + Mat dst0 = dst[0], dst1 = dst[1], dst2 = dst[2], dst3 = dst[3], dst4 = dst[4]; + + SANITY_CHECK(dst0, eps); + SANITY_CHECK(dst1, eps); + SANITY_CHECK(dst2, eps); + SANITY_CHECK(dst3, eps); + SANITY_CHECK(dst4, eps); +} From 793e980876a134ae948b83c1d8caaaeb122a6bc3 Mon Sep 17 00:00:00 2001 From: Alexander Karsakov Date: Wed, 16 Apr 2014 16:00:07 +0400 Subject: [PATCH 4/7] Added IPP Pyramid API functions to cv::buildPyramid --- modules/imgproc/perf/perf_pyramids.cpp | 14 ++-- modules/imgproc/src/pyramids.cpp | 97 ++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 11 deletions(-) diff --git a/modules/imgproc/perf/perf_pyramids.cpp b/modules/imgproc/perf/perf_pyramids.cpp index 1310239bf1..8062297594 100644 --- a/modules/imgproc/perf/perf_pyramids.cpp +++ b/modules/imgproc/perf/perf_pyramids.cpp @@ -45,8 +45,8 @@ PERF_TEST_P(Size_MatType, pyrUp, testing::Combine( } PERF_TEST_P(Size_MatType, buildPyramid, testing::Combine( - testing::Values(sz2160p, sz1080p, sz720p, szVGA, szQVGA, szODD), - testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4) + testing::Values(sz1080p, sz720p, szVGA, szQVGA, szODD), + testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4) ) ) { @@ -64,9 +64,9 @@ PERF_TEST_P(Size_MatType, buildPyramid, testing::Combine( Mat dst0 = dst[0], dst1 = dst[1], dst2 = dst[2], dst3 = dst[3], dst4 = dst[4]; - SANITY_CHECK(dst0, eps); - SANITY_CHECK(dst1, eps); - SANITY_CHECK(dst2, eps); - SANITY_CHECK(dst3, eps); - SANITY_CHECK(dst4, eps); + SANITY_CHECK(dst0, eps, ERROR_RELATIVE); + SANITY_CHECK(dst1, eps, ERROR_RELATIVE); + SANITY_CHECK(dst2, eps, ERROR_RELATIVE); + SANITY_CHECK(dst3, eps, ERROR_RELATIVE); + SANITY_CHECK(dst4, eps, ERROR_RELATIVE); } diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index 3f51908348..a984f25425 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -585,9 +585,9 @@ void cv::pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int borderT int type = src.type(); CV_SUPPRESS_DEPRECATED_START ippiPyrUp pyrUpFunc = type == CV_8UC1 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_8u_C1R : - type == CV_8UC3 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_8u_C3R : - type == CV_32FC1 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_32f_C1R : - type == CV_32FC3 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_32f_C3R : 0; + type == CV_8UC3 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_8u_C3R : + type == CV_32FC1 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_32f_C1R : + type == CV_32FC3 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_32f_C3R : 0; CV_SUPPRESS_DEPRECATED_END if (pyrUpFunc) @@ -643,7 +643,96 @@ void cv::buildPyramid( InputArray _src, OutputArrayOfArrays _dst, int maxlevel, Mat src = _src.getMat(); _dst.create( maxlevel + 1, 1, 0 ); _dst.getMatRef(0) = src; - for( int i = 1; i <= maxlevel; i++ ) + + int i=1; + +#if (defined(HAVE_IPP) && !defined(HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 801) + bool isolated = (borderType & BORDER_ISOLATED) != 0; + int borderTypeNI = borderType & ~BORDER_ISOLATED; + if (borderTypeNI == BORDER_DEFAULT && (!src.isSubmatrix() || isolated)) + { + typedef IppStatus (CV_STDCALL * ippiPyramidLayerDownInitAlloc)(void** ppState, IppiSize srcRoi, Ipp32f rate, void* pKernel, int kerSize, int mode); + typedef IppStatus (CV_STDCALL * ippiPyramidLayerDown)(void* pSrc, int srcStep, IppiSize srcRoiSize, void* pDst, int dstStep, IppiSize dstRoiSize, void* pState); + typedef IppStatus (CV_STDCALL * ippiPyramidLayerDownFree)(void* pState); + + int type = src.type(); + int depth = src.depth(); + ippiPyramidLayerDownInitAlloc pyrInitAllocFunc = 0; + ippiPyramidLayerDown pyrDownFunc = 0; + ippiPyramidLayerDownFree pyrFreeFunc = 0; + + if (type == CV_8UC1) + { + pyrInitAllocFunc = (ippiPyramidLayerDownInitAlloc) ippiPyramidLayerDownInitAlloc_8u_C1R; + pyrDownFunc = (ippiPyramidLayerDown) ippiPyramidLayerDown_8u_C1R; + pyrFreeFunc = (ippiPyramidLayerDownFree) ippiPyramidLayerDownFree_8u_C1R; + } else if (type == CV_8UC3) + { + pyrInitAllocFunc = (ippiPyramidLayerDownInitAlloc) ippiPyramidLayerDownInitAlloc_8u_C3R; + pyrDownFunc = (ippiPyramidLayerDown) ippiPyramidLayerDown_8u_C3R; + pyrFreeFunc = (ippiPyramidLayerDownFree) ippiPyramidLayerDownFree_8u_C3R; + } else if (type == CV_16UC1) + { + pyrInitAllocFunc = (ippiPyramidLayerDownInitAlloc) ippiPyramidLayerDownInitAlloc_16u_C1R; + pyrDownFunc = (ippiPyramidLayerDown) ippiPyramidLayerDown_16u_C1R; + pyrFreeFunc = (ippiPyramidLayerDownFree) ippiPyramidLayerDownFree_16u_C1R; + } else if (type == CV_16UC3) + { + pyrInitAllocFunc = (ippiPyramidLayerDownInitAlloc) ippiPyramidLayerDownInitAlloc_16u_C3R; + pyrDownFunc = (ippiPyramidLayerDown) ippiPyramidLayerDown_16u_C3R; + pyrFreeFunc = (ippiPyramidLayerDownFree) ippiPyramidLayerDownFree_16u_C3R; + } else if (type == CV_32FC1) + { + pyrInitAllocFunc = (ippiPyramidLayerDownInitAlloc) ippiPyramidLayerDownInitAlloc_32f_C1R; + pyrDownFunc = (ippiPyramidLayerDown) ippiPyramidLayerDown_32f_C1R; + pyrFreeFunc = (ippiPyramidLayerDownFree) ippiPyramidLayerDownFree_32f_C1R; + } else if (type == CV_32FC3) + { + pyrInitAllocFunc = (ippiPyramidLayerDownInitAlloc) ippiPyramidLayerDownInitAlloc_32f_C3R; + pyrDownFunc = (ippiPyramidLayerDown) ippiPyramidLayerDown_32f_C3R; + pyrFreeFunc = (ippiPyramidLayerDownFree) ippiPyramidLayerDownFree_32f_C3R; + } + + if (pyrInitAllocFunc && pyrDownFunc && pyrFreeFunc) + { + float rate = 2.f; + IppiSize srcRoi = { src.cols, src.rows }; + IppiPyramid *gPyr; + IppStatus ok = ippiPyramidInitAlloc(&gPyr, maxlevel + 1, srcRoi, rate); + + Ipp16s iKernel[5] = { 1, 4, 6, 4, 1 }; + Ipp32f fKernel[5] = { 1.f, 4.f, 6.f, 4.f, 1.f }; + void* kernel = depth >= CV_32F ? (void*) fKernel : (void*) iKernel; + + if (ok >= 0) ok = pyrInitAllocFunc((void**) &(gPyr->pState), srcRoi, rate, kernel, 5, IPPI_INTER_LINEAR); + if (ok >= 0) + { + gPyr->pImage[0] = src.data; + gPyr->pStep[0] = (int) src.step; + gPyr->pRoi[0] = srcRoi; + for( ; i <= maxlevel; i++ ) + { + IppiSize dstRoi; + ok = ippiGetPyramidDownROI(gPyr->pRoi[i-1], &dstRoi, rate); + Mat& dst = _dst.getMatRef(i); + dst.create(Size(dstRoi.width, dstRoi.height), type); + gPyr->pImage[i] = dst.data; + gPyr->pStep[i] = (int) dst.step; + gPyr->pRoi[i] = dstRoi; + + if (ok >= 0) ok = pyrDownFunc(gPyr->pImage[i-1], gPyr->pStep[i-1], gPyr->pRoi[i-1], + gPyr->pImage[i], gPyr->pStep[i], gPyr->pRoi[i], gPyr->pState); + + if (ok < 0) + break; + } + pyrFreeFunc(gPyr->pState); + } + ippiPyramidFree(gPyr); + } + } +#endif + for( ; i <= maxlevel; i++ ) pyrDown( _dst.getMatRef(i-1), _dst.getMatRef(i), Size(), borderType ); } From a7d12aabab3b8396984e8cdbc6768b6c8eb53482 Mon Sep 17 00:00:00 2001 From: Alexander Karsakov Date: Wed, 16 Apr 2014 18:07:24 +0400 Subject: [PATCH 5/7] Added epsilon for tests with float data type --- modules/imgproc/perf/perf_pyramids.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/imgproc/perf/perf_pyramids.cpp b/modules/imgproc/perf/perf_pyramids.cpp index 8062297594..9ee1040cb2 100644 --- a/modules/imgproc/perf/perf_pyramids.cpp +++ b/modules/imgproc/perf/perf_pyramids.cpp @@ -14,6 +14,7 @@ PERF_TEST_P(Size_MatType, pyrDown, testing::Combine( { Size sz = get<0>(GetParam()); int matType = get<1>(GetParam()); + const double eps = CV_MAT_DEPTH(matType) <= CV_32S ? 1 : 1e-5; Mat src(sz, matType); Mat dst((sz.height + 1)/2, (sz.width + 1)/2, matType); @@ -22,7 +23,7 @@ PERF_TEST_P(Size_MatType, pyrDown, testing::Combine( TEST_CYCLE() pyrDown(src, dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, eps, ERROR_RELATIVE); } PERF_TEST_P(Size_MatType, pyrUp, testing::Combine( @@ -33,6 +34,7 @@ PERF_TEST_P(Size_MatType, pyrUp, testing::Combine( { Size sz = get<0>(GetParam()); int matType = get<1>(GetParam()); + const double eps = CV_MAT_DEPTH(matType) <= CV_32S ? 1 : 1e-5; Mat src(sz, matType); Mat dst(sz.height*2, sz.width*2, matType); @@ -41,7 +43,7 @@ PERF_TEST_P(Size_MatType, pyrUp, testing::Combine( TEST_CYCLE() pyrUp(src, dst); - SANITY_CHECK(dst); + SANITY_CHECK(dst, eps, ERROR_RELATIVE); } PERF_TEST_P(Size_MatType, buildPyramid, testing::Combine( From 6202f54a1842cc304357e383211987948db72da1 Mon Sep 17 00:00:00 2001 From: Alexander Karsakov Date: Thu, 17 Apr 2014 19:02:56 +0400 Subject: [PATCH 6/7] Fixed sanity check for integer type --- modules/imgproc/perf/perf_pyramids.cpp | 20 +++++++++++--------- modules/imgproc/src/pyramids.cpp | 10 ---------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/modules/imgproc/perf/perf_pyramids.cpp b/modules/imgproc/perf/perf_pyramids.cpp index 9ee1040cb2..e23af8eade 100644 --- a/modules/imgproc/perf/perf_pyramids.cpp +++ b/modules/imgproc/perf/perf_pyramids.cpp @@ -15,6 +15,7 @@ PERF_TEST_P(Size_MatType, pyrDown, testing::Combine( Size sz = get<0>(GetParam()); int matType = get<1>(GetParam()); const double eps = CV_MAT_DEPTH(matType) <= CV_32S ? 1 : 1e-5; + perf::ERROR_TYPE error_type = CV_MAT_DEPTH(matType) <= CV_32S ? ERROR_ABSOLUTE : ERROR_RELATIVE; Mat src(sz, matType); Mat dst((sz.height + 1)/2, (sz.width + 1)/2, matType); @@ -23,7 +24,7 @@ PERF_TEST_P(Size_MatType, pyrDown, testing::Combine( TEST_CYCLE() pyrDown(src, dst); - SANITY_CHECK(dst, eps, ERROR_RELATIVE); + SANITY_CHECK(dst, eps, error_type); } PERF_TEST_P(Size_MatType, pyrUp, testing::Combine( @@ -35,6 +36,7 @@ PERF_TEST_P(Size_MatType, pyrUp, testing::Combine( Size sz = get<0>(GetParam()); int matType = get<1>(GetParam()); const double eps = CV_MAT_DEPTH(matType) <= CV_32S ? 1 : 1e-5; + perf::ERROR_TYPE error_type = CV_MAT_DEPTH(matType) <= CV_32S ? ERROR_ABSOLUTE : ERROR_RELATIVE; Mat src(sz, matType); Mat dst(sz.height*2, sz.width*2, matType); @@ -43,12 +45,12 @@ PERF_TEST_P(Size_MatType, pyrUp, testing::Combine( TEST_CYCLE() pyrUp(src, dst); - SANITY_CHECK(dst, eps, ERROR_RELATIVE); + SANITY_CHECK(dst, eps, error_type); } PERF_TEST_P(Size_MatType, buildPyramid, testing::Combine( testing::Values(sz1080p, sz720p, szVGA, szQVGA, szODD), - testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4) + testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4) ) ) { @@ -56,7 +58,7 @@ PERF_TEST_P(Size_MatType, buildPyramid, testing::Combine( int matType = get<1>(GetParam()); int maxLevel = 5; const double eps = CV_MAT_DEPTH(matType) <= CV_32S ? 1 : 1e-5; - + perf::ERROR_TYPE error_type = CV_MAT_DEPTH(matType) <= CV_32S ? ERROR_ABSOLUTE : ERROR_RELATIVE; Mat src(sz, matType); std::vector dst(maxLevel); @@ -66,9 +68,9 @@ PERF_TEST_P(Size_MatType, buildPyramid, testing::Combine( Mat dst0 = dst[0], dst1 = dst[1], dst2 = dst[2], dst3 = dst[3], dst4 = dst[4]; - SANITY_CHECK(dst0, eps, ERROR_RELATIVE); - SANITY_CHECK(dst1, eps, ERROR_RELATIVE); - SANITY_CHECK(dst2, eps, ERROR_RELATIVE); - SANITY_CHECK(dst3, eps, ERROR_RELATIVE); - SANITY_CHECK(dst4, eps, ERROR_RELATIVE); + SANITY_CHECK(dst0, eps, error_type); + SANITY_CHECK(dst1, eps, error_type); + SANITY_CHECK(dst2, eps, error_type); + SANITY_CHECK(dst3, eps, error_type); + SANITY_CHECK(dst4, eps, error_type); } diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index a984f25425..02e03c0c52 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -671,16 +671,6 @@ void cv::buildPyramid( InputArray _src, OutputArrayOfArrays _dst, int maxlevel, pyrInitAllocFunc = (ippiPyramidLayerDownInitAlloc) ippiPyramidLayerDownInitAlloc_8u_C3R; pyrDownFunc = (ippiPyramidLayerDown) ippiPyramidLayerDown_8u_C3R; pyrFreeFunc = (ippiPyramidLayerDownFree) ippiPyramidLayerDownFree_8u_C3R; - } else if (type == CV_16UC1) - { - pyrInitAllocFunc = (ippiPyramidLayerDownInitAlloc) ippiPyramidLayerDownInitAlloc_16u_C1R; - pyrDownFunc = (ippiPyramidLayerDown) ippiPyramidLayerDown_16u_C1R; - pyrFreeFunc = (ippiPyramidLayerDownFree) ippiPyramidLayerDownFree_16u_C1R; - } else if (type == CV_16UC3) - { - pyrInitAllocFunc = (ippiPyramidLayerDownInitAlloc) ippiPyramidLayerDownInitAlloc_16u_C3R; - pyrDownFunc = (ippiPyramidLayerDown) ippiPyramidLayerDown_16u_C3R; - pyrFreeFunc = (ippiPyramidLayerDownFree) ippiPyramidLayerDownFree_16u_C3R; } else if (type == CV_32FC1) { pyrInitAllocFunc = (ippiPyramidLayerDownInitAlloc) ippiPyramidLayerDownInitAlloc_32f_C1R; From 4f4a95299af1531e5fb35fac3d18d724ca30a133 Mon Sep 17 00:00:00 2001 From: Alexander Karsakov Date: Fri, 18 Apr 2014 09:04:25 +0400 Subject: [PATCH 7/7] Added setIppErrorStatus --- modules/imgproc/src/pyramids.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index 02e03c0c52..277a36ae5c 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -538,6 +538,7 @@ void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borde if (ok >= 0) return; + setIppErrorStatus(); } } } @@ -606,6 +607,7 @@ void cv::pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int borderT if (ok >= 0) return; + setIppErrorStatus(); } } } @@ -714,9 +716,15 @@ void cv::buildPyramid( InputArray _src, OutputArrayOfArrays _dst, int maxlevel, gPyr->pImage[i], gPyr->pStep[i], gPyr->pRoi[i], gPyr->pState); if (ok < 0) + { + setIppErrorStatus(); break; + } } pyrFreeFunc(gPyr->pState); + } else + { + setIppErrorStatus(); } ippiPyramidFree(gPyr); }