From f8484e32665e065ee3c319d7372e051575b79cf9 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 26 Feb 2015 19:34:20 +0300 Subject: [PATCH 1/9] add fucntion to control tegra optimizations in run-time --- modules/core/include/opencv2/core/private.hpp | 9 ++++++ modules/core/src/precomp.hpp | 6 ++++ modules/core/src/system.cpp | 30 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/modules/core/include/opencv2/core/private.hpp b/modules/core/include/opencv2/core/private.hpp index 38d18e3000..ececd30f2a 100644 --- a/modules/core/include/opencv2/core/private.hpp +++ b/modules/core/include/opencv2/core/private.hpp @@ -269,6 +269,15 @@ typedef enum CvStatus } CvStatus; +#ifdef HAVE_TEGRA_OPTIMIZATION +namespace cv { namespace tegra { + +CV_EXPORTS bool useTegra(); +CV_EXPORTS void setUseTegra(bool flag); + +} +#endif + //! @endcond #endif // __OPENCV_CORE_PRIVATE_HPP__ diff --git a/modules/core/src/precomp.hpp b/modules/core/src/precomp.hpp index b35be6ecc2..a57849012c 100644 --- a/modules/core/src/precomp.hpp +++ b/modules/core/src/precomp.hpp @@ -236,6 +236,9 @@ struct CoreTLSData { CoreTLSData() : device(0), useOpenCL(-1), useIPP(-1), useCollection(false) { +#ifdef HAVE_TEGRA_OPTIMIZATION + useTegra = -1; +#endif #ifdef CV_COLLECT_IMPL_DATA implFlags = 0; #endif @@ -246,6 +249,9 @@ struct CoreTLSData ocl::Queue oclQueue; int useOpenCL; // 1 - use, 0 - do not use, -1 - auto/not initialized int useIPP; // 1 - use, 0 - do not use, -1 - auto/not initialized +#ifdef HAVE_TEGRA_OPTIMIZATION + int useTegra; // 1 - use, 0 - do not use, -1 - auto/not initialized +#endif bool useCollection; // enable/disable impl data collection #ifdef CV_COLLECT_IMPL_DATA diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 43d5bd0a0b..3aea4571fd 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1257,6 +1257,36 @@ void setUseIPP(bool flag) } // namespace ipp +#ifdef HAVE_TEGRA_OPTIMIZATION + +namespace tegra { + +bool useTegra() +{ + CoreTLSData* data = getCoreTlsData().get(); + + if (data->useTegra < 0) + { + const char* pTegraEnv = getenv("OPENCV_TEGRA"); + if (pTegraEnv && (cv::String(pTegraEnv) == "disabled")) + data->useTegra = false; + else + data->useTegra = true; + } + + return (data->useTegra > 0); +} + +void setUseTegra(bool flag) +{ + CoreTLSData* data = getCoreTlsData().get(); + data->useTegra = flag; +} + +} // namespace tegra + +#endif + } // namespace cv /* End of file. */ From 44e41baffed13c7a749cffe111402bf3f84fef1e Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 26 Feb 2015 19:34:58 +0300 Subject: [PATCH 2/9] use new functions before all tegra:: calls --- modules/calib3d/src/circlesgrid.cpp | 2 +- modules/core/src/arithm.cpp | 79 +++++++++++++------------ modules/core/src/mathfuncs.cpp | 2 +- modules/features2d/src/fast.cpp | 2 +- modules/imgproc/src/canny.cpp | 2 +- modules/imgproc/src/color.cpp | 21 ++++--- modules/imgproc/src/corner.cpp | 2 +- modules/imgproc/src/deriv.cpp | 6 +- modules/imgproc/src/filter.cpp | 2 +- modules/imgproc/src/imgwarp.cpp | 6 +- modules/imgproc/src/pyramids.cpp | 4 +- modules/imgproc/src/smooth.cpp | 6 +- modules/imgproc/src/templmatch.cpp | 2 +- modules/imgproc/src/thresh.cpp | 6 +- modules/objdetect/src/cascadedetect.cpp | 3 +- modules/photo/src/denoising.cpp | 2 +- modules/stitching/src/blenders.cpp | 4 +- modules/stitching/src/matchers.cpp | 2 +- modules/ts/src/ts_func.cpp | 2 +- modules/video/src/lkpyramid.cpp | 2 +- 20 files changed, 82 insertions(+), 75 deletions(-) diff --git a/modules/calib3d/src/circlesgrid.cpp b/modules/calib3d/src/circlesgrid.cpp index bda50c05fa..7fe60ef92a 100644 --- a/modules/calib3d/src/circlesgrid.cpp +++ b/modules/calib3d/src/circlesgrid.cpp @@ -69,7 +69,7 @@ void drawPoints(const std::vector &points, Mat &outImage, int radius = void CirclesGridClusterFinder::hierarchicalClustering(const std::vector &points, const Size &patternSz, std::vector &patternPoints) { #ifdef HAVE_TEGRA_OPTIMIZATION - if(tegra::hierarchicalClustering(points, patternSz, patternPoints)) + if(cv::tegra::useTegra() && tegra::hierarchicalClustering(points, patternSz, patternPoints)) return; #endif int j, n = (int)points.size(); diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index c4de2c4bed..02ef627c24 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -2256,51 +2256,54 @@ void cv::subtract( InputArray _src1, InputArray _src2, OutputArray _dst, InputArray mask, int dtype ) { #ifdef HAVE_TEGRA_OPTIMIZATION - int kind1 = _src1.kind(), kind2 = _src2.kind(); - Mat src1 = _src1.getMat(), src2 = _src2.getMat(); - bool src1Scalar = checkScalar(src1, _src2.type(), kind1, kind2); - bool src2Scalar = checkScalar(src2, _src1.type(), kind2, kind1); - - if (!src1Scalar && !src2Scalar && - src1.depth() == CV_8U && src2.type() == src1.type() && - src1.dims == 2 && src2.size() == src1.size() && - mask.empty()) + if (cv::tegra::useTegra()) { - if (dtype < 0) + int kind1 = _src1.kind(), kind2 = _src2.kind(); + Mat src1 = _src1.getMat(), src2 = _src2.getMat(); + bool src1Scalar = checkScalar(src1, _src2.type(), kind1, kind2); + bool src2Scalar = checkScalar(src2, _src1.type(), kind2, kind1); + + if (!src1Scalar && !src2Scalar && + src1.depth() == CV_8U && src2.type() == src1.type() && + src1.dims == 2 && src2.size() == src1.size() && + mask.empty()) { - if (_dst.fixedType()) + if (dtype < 0) { - dtype = _dst.depth(); + if (_dst.fixedType()) + { + dtype = _dst.depth(); + } + else + { + dtype = src1.depth(); + } } - else - { - dtype = src1.depth(); - } - } - dtype = CV_MAT_DEPTH(dtype); + dtype = CV_MAT_DEPTH(dtype); - if (!_dst.fixedType() || dtype == _dst.depth()) - { - _dst.create(src1.size(), CV_MAKE_TYPE(dtype, src1.channels())); + if (!_dst.fixedType() || dtype == _dst.depth()) + { + _dst.create(src1.size(), CV_MAKE_TYPE(dtype, src1.channels())); - if (dtype == CV_16S) - { - Mat dst = _dst.getMat(); - if(tegra::subtract_8u8u16s(src1, src2, dst)) - return; - } - else if (dtype == CV_32F) - { - Mat dst = _dst.getMat(); - if(tegra::subtract_8u8u32f(src1, src2, dst)) - return; - } - else if (dtype == CV_8S) - { - Mat dst = _dst.getMat(); - if(tegra::subtract_8u8u8s(src1, src2, dst)) - return; + if (dtype == CV_16S) + { + Mat dst = _dst.getMat(); + if(tegra::subtract_8u8u16s(src1, src2, dst)) + return; + } + else if (dtype == CV_32F) + { + Mat dst = _dst.getMat(); + if(tegra::subtract_8u8u32f(src1, src2, dst)) + return; + } + else if (dtype == CV_8S) + { + Mat dst = _dst.getMat(); + if(tegra::subtract_8u8u8s(src1, src2, dst)) + return; + } } } } diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index 13ada1d1d6..f1bb0c2126 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -127,7 +127,7 @@ static void FastAtan2_32f(const float *Y, const float *X, float *angle, int len, float scale = angleInDegrees ? 1 : (float)(CV_PI/180); #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::FastAtan2_32f(Y, X, angle, len, scale)) + if (cv::tegra::useTegra() && tegra::FastAtan2_32f(Y, X, angle, len, scale)) return; #endif diff --git a/modules/features2d/src/fast.cpp b/modules/features2d/src/fast.cpp index 767b74aff6..b82572bbeb 100644 --- a/modules/features2d/src/fast.cpp +++ b/modules/features2d/src/fast.cpp @@ -346,7 +346,7 @@ void FAST(InputArray _img, std::vector& keypoints, int threshold, bool break; case FastFeatureDetector::TYPE_9_16: #ifdef HAVE_TEGRA_OPTIMIZATION - if(tegra::FAST(_img, keypoints, threshold, nonmax_suppression)) + if(cv::tegra::useTegra() && tegra::FAST(_img, keypoints, threshold, nonmax_suppression)) break; #endif FAST_t<16>(_img, keypoints, threshold, nonmax_suppression); diff --git a/modules/imgproc/src/canny.cpp b/modules/imgproc/src/canny.cpp index 233218b3e2..2bc9de426e 100644 --- a/modules/imgproc/src/canny.cpp +++ b/modules/imgproc/src/canny.cpp @@ -261,7 +261,7 @@ void cv::Canny( InputArray _src, OutputArray _dst, Mat src = _src.getMat(), dst = _dst.getMat(); #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::canny(src, dst, low_thresh, high_thresh, aperture_size, L2gradient)) + if (cv::tegra::useTegra() && tegra::canny(src, dst, low_thresh, high_thresh, aperture_size, L2gradient)) return; #endif diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp index b900cf1845..c464e8234a 100644 --- a/modules/imgproc/src/color.cpp +++ b/modules/imgproc/src/color.cpp @@ -6128,7 +6128,7 @@ struct YUV420sp2RGB888Invoker : ParallelLoopBody const uchar* y1 = my1 + rangeBegin * stride, *uv = muv + rangeBegin * stride / 2; #ifdef HAVE_TEGRA_OPTIMIZATION - if(tegra::cvtYUV4202RGB(bIdx, uIdx, 3, y1, uv, stride, dst->ptr(rangeBegin), dst->step, rangeEnd - rangeBegin, dst->cols)) + if(cv::tegra::useTegra() && tegra::cvtYUV4202RGB(bIdx, uIdx, 3, y1, uv, stride, dst->ptr(rangeBegin), dst->step, rangeEnd - rangeBegin, dst->cols)) return; #endif @@ -6197,7 +6197,7 @@ struct YUV420sp2RGBA8888Invoker : ParallelLoopBody const uchar* y1 = my1 + rangeBegin * stride, *uv = muv + rangeBegin * stride / 2; #ifdef HAVE_TEGRA_OPTIMIZATION - if(tegra::cvtYUV4202RGB(bIdx, uIdx, 4, y1, uv, stride, dst->ptr(rangeBegin), dst->step, rangeEnd - rangeBegin, dst->cols)) + if(cv::tegra::useTegra() && tegra::cvtYUV4202RGB(bIdx, uIdx, 4, y1, uv, stride, dst->ptr(rangeBegin), dst->step, rangeEnd - rangeBegin, dst->cols)) return; #endif @@ -7418,9 +7418,10 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) if( depth == CV_8U ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if(!tegra::cvtBGR2RGB(src, dst, bidx)) + if(cv::tegra::useTegra() && tegra::cvtBGR2RGB(src, dst, bidx)) + break; #endif - CvtColorLoop(src, dst, RGB2RGB(scn, dcn, bidx)); + CvtColorLoop(src, dst, RGB2RGB(scn, dcn, bidx)); } else if( depth == CV_16U ) CvtColorLoop(src, dst, RGB2RGB(scn, dcn, bidx)); @@ -7485,7 +7486,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) #ifdef HAVE_TEGRA_OPTIMIZATION if(code == CV_BGR2BGR565 || code == CV_BGRA2BGR565 || code == CV_RGB2BGR565 || code == CV_RGBA2BGR565) - if(tegra::cvtRGB2RGB565(src, dst, code == CV_RGB2BGR565 || code == CV_RGBA2BGR565 ? 0 : 2)) + if(cv::tegra::useTegra() && tegra::cvtRGB2RGB565(src, dst, code == CV_RGB2BGR565 || code == CV_RGBA2BGR565 ? 0 : 2)) break; #endif @@ -7611,7 +7612,8 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) if( depth == CV_8U ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if(!tegra::cvtRGB2Gray(src, dst, bidx)) + if(cv::tegra::useTegra() && tegra::cvtRGB2Gray(src, dst, bidx)) + break; #endif CvtColorLoop(src, dst, RGB2Gray(scn, bidx, 0)); } @@ -7663,7 +7665,8 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) if( depth == CV_8U ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if(!tegra::cvtGray2RGB(src, dst)) + if(cv::tegra::useTegra() && tegra::cvtGray2RGB(src, dst)) + break; #endif CvtColorLoop(src, dst, Gray2RGB(dcn)); } @@ -7742,7 +7745,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) if( depth == CV_8U ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if((code == CV_RGB2YCrCb || code == CV_BGR2YCrCb) && tegra::cvtRGB2YCrCb(src, dst, bidx)) + if((code == CV_RGB2YCrCb || code == CV_BGR2YCrCb) && cv::tegra::useTegra() && tegra::cvtRGB2YCrCb(src, dst, bidx)) break; #endif CvtColorLoop(src, dst, RGB2YCrCb_i(scn, bidx, coeffs_i)); @@ -8036,7 +8039,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) code == CV_BGR2HSV_FULL || code == CV_RGB2HSV_FULL ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if(tegra::cvtRGB2HSV(src, dst, bidx, hrange)) + if(cv::tegra::useTegra() && tegra::cvtRGB2HSV(src, dst, bidx, hrange)) break; #endif if( depth == CV_8U ) diff --git a/modules/imgproc/src/corner.cpp b/modules/imgproc/src/corner.cpp index 2e9400409f..a5d2442efe 100644 --- a/modules/imgproc/src/corner.cpp +++ b/modules/imgproc/src/corner.cpp @@ -269,7 +269,7 @@ cornerEigenValsVecs( const Mat& src, Mat& eigenv, int block_size, int borderType=BORDER_DEFAULT ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::cornerEigenValsVecs(src, eigenv, block_size, aperture_size, op_type, k, borderType)) + if (cv::tegra::useTegra() && tegra::cornerEigenValsVecs(src, eigenv, block_size, aperture_size, op_type, k, borderType)) return; #endif #if CV_SSE2 diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index 34721e2d62..ef28441d05 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -562,7 +562,7 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, _dst.create( _src.size(), dtype ); #ifdef HAVE_TEGRA_OPTIMIZATION - if (scale == 1.0 && delta == 0) + if (cv::tegra::useTegra() && scale == 1.0 && delta == 0) { Mat src = _src.getMat(), dst = _dst.getMat(); if (ksize == 3 && tegra::sobel3x3(src, dst, dx, dy, borderType)) @@ -620,7 +620,7 @@ void cv::Scharr( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, _dst.create( _src.size(), dtype ); #ifdef HAVE_TEGRA_OPTIMIZATION - if (scale == 1.0 && delta == 0) + if (cv::tegra::useTegra() && scale == 1.0 && delta == 0) { Mat src = _src.getMat(), dst = _dst.getMat(); if (tegra::scharr(src, dst, dx, dy, borderType)) @@ -873,7 +873,7 @@ void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize, #endif #ifdef HAVE_TEGRA_OPTIMIZATION - if (scale == 1.0 && delta == 0) + if (cv::tegra::useTegra() && scale == 1.0 && delta == 0) { Mat src = _src.getMat(), dst = _dst.getMat(); if (ksize == 1 && tegra::laplace1(src, dst, borderType)) diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 63a1005ae7..700ec68170 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -4659,7 +4659,7 @@ void cv::filter2D( InputArray _src, OutputArray _dst, int ddepth, #endif #ifdef HAVE_TEGRA_OPTIMIZATION - if( tegra::filter2D(src, dst, kernel, anchor, delta, borderType) ) + if( cv::tegra::useTegra() && tegra::filter2D(src, dst, kernel, anchor, delta, borderType) ) return; #endif diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index fe126fbbd1..511fc5aea5 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -3227,7 +3227,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize, Mat dst = _dst.getMat(); #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::resize(src, dst, (float)inv_scale_x, (float)inv_scale_y, interpolation)) + if (cv::tegra::useTegra() && tegra::resize(src, dst, (float)inv_scale_x, (float)inv_scale_y, interpolation)) return; #endif @@ -5572,7 +5572,7 @@ void cv::warpAffine( InputArray _src, OutputArray _dst, M0.convertTo(matM, matM.type()); #ifdef HAVE_TEGRA_OPTIMIZATION - if( tegra::warpAffine(src, dst, M, flags, borderType, borderValue) ) + if( cv::tegra::useTegra() && tegra::warpAffine(src, dst, M, flags, borderType, borderValue) ) return; #endif @@ -6098,7 +6098,7 @@ void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0, M0.convertTo(matM, matM.type()); #ifdef HAVE_TEGRA_OPTIMIZATION - if( tegra::warpPerspective(src, dst, M, flags, borderType, borderValue) ) + if( cv::tegra::useTegra() && tegra::warpPerspective(src, dst, M, flags, borderType, borderValue) ) return; #endif diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index 4271b942ae..c45c33429c 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -1180,7 +1180,7 @@ void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borde int depth = src.depth(); #ifdef HAVE_TEGRA_OPTIMIZATION - if(borderType == BORDER_DEFAULT && tegra::pyrDown(src, dst)) + if(borderType == BORDER_DEFAULT && cv::tegra::useTegra() && tegra::pyrDown(src, dst)) return; #endif @@ -1257,7 +1257,7 @@ void cv::pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int borderT int depth = src.depth(); #ifdef HAVE_TEGRA_OPTIMIZATION - if(borderType == BORDER_DEFAULT && tegra::pyrUp(src, dst)) + if(borderType == BORDER_DEFAULT && cv::tegra::useTegra() && tegra::pyrUp(src, dst)) return; #endif diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 7d8b263bda..b901314095 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1324,7 +1324,7 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, ksize.width = 1; } #ifdef HAVE_TEGRA_OPTIMIZATION - if ( tegra::box(src, dst, ksize, anchor, normalize, borderType) ) + if ( cv::tegra::useTegra() && tegra::box(src, dst, ksize, anchor, normalize, borderType) ) return; #endif @@ -1650,7 +1650,7 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, #ifdef HAVE_TEGRA_OPTIMIZATION Mat src = _src.getMat(); Mat dst = _dst.getMat(); - if(sigma1 == 0 && sigma2 == 0 && tegra::gaussian(src, dst, ksize, borderType)) + if(sigma1 == 0 && sigma2 == 0 && cv::tegra::useTegra() && tegra::gaussian(src, dst, ksize, borderType)) return; #endif @@ -2698,7 +2698,7 @@ void cv::medianBlur( InputArray _src0, OutputArray _dst, int ksize ) #endif #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::medianBlur(src0, dst, ksize)) + if (cv::tegra::useTegra() && tegra::medianBlur(src0, dst, ksize)) return; #endif diff --git a/modules/imgproc/src/templmatch.cpp b/modules/imgproc/src/templmatch.cpp index 8afdba7d10..726ec53f7b 100644 --- a/modules/imgproc/src/templmatch.cpp +++ b/modules/imgproc/src/templmatch.cpp @@ -933,7 +933,7 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result, Mat result = _result.getMat(); #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::matchTemplate(img, templ, result, method)) + if (cv::tegra::useTegra() && tegra::matchTemplate(img, templ, result, method)) return; #endif diff --git a/modules/imgproc/src/thresh.cpp b/modules/imgproc/src/thresh.cpp index 03105dd042..8ef7fef8be 100644 --- a/modules/imgproc/src/thresh.cpp +++ b/modules/imgproc/src/thresh.cpp @@ -64,7 +64,7 @@ thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type ) } #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::thresh_8u(_src, _dst, roi.width, roi.height, thresh, maxval, type)) + if (cv::tegra::useTegra() && tegra::thresh_8u(_src, _dst, roi.width, roi.height, thresh, maxval, type)) return; #endif @@ -408,7 +408,7 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type ) } #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::thresh_16s(_src, _dst, roi.width, roi.height, thresh, maxval, type)) + if (cv::tegra::useTegra() && tegra::thresh_16s(_src, _dst, roi.width, roi.height, thresh, maxval, type)) return; #endif @@ -676,7 +676,7 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type ) } #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::thresh_32f(_src, _dst, roi.width, roi.height, thresh, maxval, type)) + if (cv::tegra::useTegra() && tegra::thresh_32f(_src, _dst, roi.width, roi.height, thresh, maxval, type)) return; #endif diff --git a/modules/objdetect/src/cascadedetect.cpp b/modules/objdetect/src/cascadedetect.cpp index dba810896e..01f83d3d8c 100644 --- a/modules/objdetect/src/cascadedetect.cpp +++ b/modules/objdetect/src/cascadedetect.cpp @@ -937,7 +937,8 @@ Ptr CascadeClassifierImpl::getMaskGenerato Ptr createFaceDetectionMaskGenerator() { #ifdef HAVE_TEGRA_OPTIMIZATION - return tegra::getCascadeClassifierMaskGenerator(); + if (cv::tegra::useTegra()) + return tegra::getCascadeClassifierMaskGenerator(); #else return Ptr(); #endif diff --git a/modules/photo/src/denoising.cpp b/modules/photo/src/denoising.cpp index a074ac136c..90b76a8ec7 100644 --- a/modules/photo/src/denoising.cpp +++ b/modules/photo/src/denoising.cpp @@ -58,7 +58,7 @@ void cv::fastNlMeansDenoising( InputArray _src, OutputArray _dst, float h, Mat dst = _dst.getMat(); #ifdef HAVE_TEGRA_OPTIMIZATION - if(tegra::fastNlMeansDenoising(src, dst, h, templateWindowSize, searchWindowSize)) + if(cv::tegra::useTegra() && tegra::fastNlMeansDenoising(src, dst, h, templateWindowSize, searchWindowSize)) return; #endif diff --git a/modules/stitching/src/blenders.cpp b/modules/stitching/src/blenders.cpp index 015ceb025f..7be914be86 100644 --- a/modules/stitching/src/blenders.cpp +++ b/modules/stitching/src/blenders.cpp @@ -481,7 +481,7 @@ void normalizeUsingWeightMap(InputArray _weight, InputOutputArray _src) #ifdef HAVE_TEGRA_OPTIMIZATION src = _src.getMat(); weight = _weight.getMat(); - if(tegra::normalizeUsingWeightMap(weight, src)) + if(cv::tegra::useTegra() && tegra::normalizeUsingWeightMap(weight, src)) return; #endif @@ -552,7 +552,7 @@ void createLaplacePyr(InputArray img, int num_levels, std::vector &pyr) { #ifdef HAVE_TEGRA_OPTIMIZATION cv::Mat imgMat = img.getMat(); - if(tegra::createLaplacePyr(imgMat, num_levels, pyr)) + if(cv::tegra::useTegra() && tegra::createLaplacePyr(imgMat, num_levels, pyr)) return; #endif diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index ee05268d78..43669b2544 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -148,7 +148,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat CV_Assert(features2.descriptors.depth() == CV_8U || features2.descriptors.depth() == CV_32F); #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::match2nearest(features1, features2, matches_info, match_conf_)) + if (cv::tegra::useTegra() && tegra::match2nearest(features1, features2, matches_info, match_conf_)) return; #endif diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index b6a832b6bb..f40b38237f 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -3068,7 +3068,7 @@ void printVersionInfo(bool useStdOut) if (useStdOut) std::cout << "CPU features: " << cpu_features << std::endl; #ifdef HAVE_TEGRA_OPTIMIZATION - const char * tegra_optimization = tegra::isDeviceSupported() ? "enabled" : "disabled"; + const char * tegra_optimization = cv::tegra::useTegra() && tegra::isDeviceSupported() ? "enabled" : "disabled"; ::testing::Test::RecordProperty("cv_tegra_optimization", tegra_optimization); if (useStdOut) std::cout << "Tegra optimization: " << tegra_optimization << std::endl; #endif diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index f0492fd501..22b65dfbda 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -58,7 +58,7 @@ static void calcSharrDeriv(const cv::Mat& src, cv::Mat& dst) dst.create(rows, cols, CV_MAKETYPE(DataType::depth, cn*2)); #ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::calcSharrDeriv(src, dst)) + if (cv::tegra::useTegra() && tegra::calcSharrDeriv(src, dst)) return; #endif From 12180bd7b1430db53340e9995b34f63496515639 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 26 Feb 2015 19:36:04 +0300 Subject: [PATCH 3/9] add generic method to disable/enable all optimizations (IPP, OpenCL, Tegra) --- modules/core/include/opencv2/core/base.hpp | 2 ++ modules/core/src/system.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index f2acaa3fb4..6ab3e75b70 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -727,6 +727,8 @@ CV_EXPORTS void setUseIPP(bool flag); } // ipp +CV_EXPORTS void setOptimizations(bool enabled); + //! @endcond //! @} core_utils diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 3aea4571fd..31f9c48849 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1287,6 +1287,15 @@ void setUseTegra(bool flag) #endif +void setOptimizations(bool enabled) +{ + cv::ipp::setUseIPP(enabled); + cv::ocl::setUseOpenCL(enabled); +#ifdef HAVE_TEGRA_OPTIMIZATION + cv::tegra::setUseTegra(enabled); +#endif +} + } // namespace cv /* End of file. */ From 57b8640a7673a125d36e164539102f8e11ffabb7 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 26 Feb 2015 19:36:13 +0300 Subject: [PATCH 4/9] disable all optimizations for CUDA tests --- modules/ts/include/opencv2/ts/cuda_test.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ts/include/opencv2/ts/cuda_test.hpp b/modules/ts/include/opencv2/ts/cuda_test.hpp index b225ab1796..2f4ee6936e 100644 --- a/modules/ts/include/opencv2/ts/cuda_test.hpp +++ b/modules/ts/include/opencv2/ts/cuda_test.hpp @@ -352,7 +352,7 @@ namespace cv { namespace cuda #ifdef HAVE_CUDA #define CV_CUDA_TEST_MAIN(resourcesubdir) \ - CV_TEST_MAIN(resourcesubdir, cvtest::parseCudaDeviceOptions(argc, argv), cvtest::printCudaInfo()) + CV_TEST_MAIN(resourcesubdir, cvtest::parseCudaDeviceOptions(argc, argv), cvtest::printCudaInfo(), cv::setOptimizations(false)) #else // HAVE_CUDA From d696fac8b8e109a6b80d519cdf2e5288ea8d698e Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 26 Feb 2015 19:49:12 +0300 Subject: [PATCH 5/9] move cuda tests from core to cudaarithm --- modules/core/test/test_main.cpp | 10 ---------- .../test/cuda => cudaarithm/test}/test_buffer_pool.cpp | 2 +- .../test/cuda => cudaarithm/test}/test_gpumat.cpp | 2 +- .../test/cuda => cudaarithm/test}/test_opengl.cpp | 2 +- .../test/cuda => cudaarithm/test}/test_stream.cpp | 2 +- 5 files changed, 4 insertions(+), 14 deletions(-) rename modules/{core/test/cuda => cudaarithm/test}/test_buffer_pool.cpp (99%) rename modules/{core/test/cuda => cudaarithm/test}/test_gpumat.cpp (99%) rename modules/{core/test/cuda => cudaarithm/test}/test_opengl.cpp (99%) rename modules/{core/test/cuda => cudaarithm/test}/test_stream.cpp (99%) diff --git a/modules/core/test/test_main.cpp b/modules/core/test/test_main.cpp index 5ddfb72348..d5400e20fd 100644 --- a/modules/core/test/test_main.cpp +++ b/modules/core/test/test_main.cpp @@ -7,14 +7,4 @@ #include "test_precomp.hpp" -#ifndef HAVE_CUDA - CV_TEST_MAIN("cv") - -#else - -#include "opencv2/ts/cuda_test.hpp" - -CV_CUDA_TEST_MAIN("cv") - -#endif diff --git a/modules/core/test/cuda/test_buffer_pool.cpp b/modules/cudaarithm/test/test_buffer_pool.cpp similarity index 99% rename from modules/core/test/cuda/test_buffer_pool.cpp rename to modules/cudaarithm/test/test_buffer_pool.cpp index eec6ed3f64..becbdd2761 100644 --- a/modules/core/test/cuda/test_buffer_pool.cpp +++ b/modules/cudaarithm/test/test_buffer_pool.cpp @@ -40,7 +40,7 @@ // //M*/ -#include "../test_precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_CUDA diff --git a/modules/core/test/cuda/test_gpumat.cpp b/modules/cudaarithm/test/test_gpumat.cpp similarity index 99% rename from modules/core/test/cuda/test_gpumat.cpp rename to modules/cudaarithm/test/test_gpumat.cpp index b549f03a05..3f63352b86 100644 --- a/modules/core/test/cuda/test_gpumat.cpp +++ b/modules/cudaarithm/test/test_gpumat.cpp @@ -40,7 +40,7 @@ // //M*/ -#include "../test_precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_CUDA diff --git a/modules/core/test/cuda/test_opengl.cpp b/modules/cudaarithm/test/test_opengl.cpp similarity index 99% rename from modules/core/test/cuda/test_opengl.cpp rename to modules/cudaarithm/test/test_opengl.cpp index f4c733d064..f300dff6bc 100644 --- a/modules/core/test/cuda/test_opengl.cpp +++ b/modules/cudaarithm/test/test_opengl.cpp @@ -40,7 +40,7 @@ // //M*/ -#include "../test_precomp.hpp" +#include "test_precomp.hpp" #if defined(HAVE_CUDA) && defined(HAVE_OPENGL) diff --git a/modules/core/test/cuda/test_stream.cpp b/modules/cudaarithm/test/test_stream.cpp similarity index 99% rename from modules/core/test/cuda/test_stream.cpp rename to modules/cudaarithm/test/test_stream.cpp index a0e451a62a..c9a5e694f2 100644 --- a/modules/core/test/cuda/test_stream.cpp +++ b/modules/cudaarithm/test/test_stream.cpp @@ -40,7 +40,7 @@ // //M*/ -#include "../test_precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_CUDA From cda6fed41fce2fab8018d85b2158e79bc4d8d8f3 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 27 Feb 2015 12:52:11 +0300 Subject: [PATCH 6/9] move tegra namespace out of cv to prevent conflicts --- modules/calib3d/src/circlesgrid.cpp | 2 +- modules/core/include/opencv2/core/private.hpp | 2 +- modules/core/src/arithm.cpp | 2 +- modules/core/src/mathfuncs.cpp | 2 +- modules/core/src/system.cpp | 14 +++++++++----- modules/features2d/src/fast.cpp | 2 +- modules/imgproc/src/canny.cpp | 2 +- modules/imgproc/src/color.cpp | 16 ++++++++-------- modules/imgproc/src/corner.cpp | 2 +- modules/imgproc/src/deriv.cpp | 6 +++--- modules/imgproc/src/filter.cpp | 2 +- modules/imgproc/src/imgwarp.cpp | 6 +++--- modules/imgproc/src/pyramids.cpp | 4 ++-- modules/imgproc/src/smooth.cpp | 6 +++--- modules/imgproc/src/templmatch.cpp | 2 +- modules/imgproc/src/thresh.cpp | 6 +++--- modules/objdetect/src/cascadedetect.cpp | 5 ++--- modules/photo/src/denoising.cpp | 2 +- modules/stitching/src/blenders.cpp | 4 ++-- modules/stitching/src/matchers.cpp | 2 +- modules/ts/src/ts_func.cpp | 2 +- modules/video/src/lkpyramid.cpp | 2 +- 22 files changed, 48 insertions(+), 45 deletions(-) diff --git a/modules/calib3d/src/circlesgrid.cpp b/modules/calib3d/src/circlesgrid.cpp index 7fe60ef92a..39abd8ac50 100644 --- a/modules/calib3d/src/circlesgrid.cpp +++ b/modules/calib3d/src/circlesgrid.cpp @@ -69,7 +69,7 @@ void drawPoints(const std::vector &points, Mat &outImage, int radius = void CirclesGridClusterFinder::hierarchicalClustering(const std::vector &points, const Size &patternSz, std::vector &patternPoints) { #ifdef HAVE_TEGRA_OPTIMIZATION - if(cv::tegra::useTegra() && tegra::hierarchicalClustering(points, patternSz, patternPoints)) + if(tegra::useTegra() && tegra::hierarchicalClustering(points, patternSz, patternPoints)) return; #endif int j, n = (int)points.size(); diff --git a/modules/core/include/opencv2/core/private.hpp b/modules/core/include/opencv2/core/private.hpp index ececd30f2a..03d69bd436 100644 --- a/modules/core/include/opencv2/core/private.hpp +++ b/modules/core/include/opencv2/core/private.hpp @@ -270,7 +270,7 @@ typedef enum CvStatus CvStatus; #ifdef HAVE_TEGRA_OPTIMIZATION -namespace cv { namespace tegra { +namespace tegra { CV_EXPORTS bool useTegra(); CV_EXPORTS void setUseTegra(bool flag); diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 02ef627c24..15b0759f77 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -2256,7 +2256,7 @@ void cv::subtract( InputArray _src1, InputArray _src2, OutputArray _dst, InputArray mask, int dtype ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra()) + if (tegra::useTegra()) { int kind1 = _src1.kind(), kind2 = _src2.kind(); Mat src1 = _src1.getMat(), src2 = _src2.getMat(); diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index f1bb0c2126..446b62731b 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -127,7 +127,7 @@ static void FastAtan2_32f(const float *Y, const float *X, float *angle, int len, float scale = angleInDegrees ? 1 : (float)(CV_PI/180); #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::FastAtan2_32f(Y, X, angle, len, scale)) + if (tegra::useTegra() && tegra::FastAtan2_32f(Y, X, angle, len, scale)) return; #endif diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 31f9c48849..74d73c44e5 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1257,13 +1257,15 @@ void setUseIPP(bool flag) } // namespace ipp +} // namespace cv + #ifdef HAVE_TEGRA_OPTIMIZATION namespace tegra { bool useTegra() { - CoreTLSData* data = getCoreTlsData().get(); + cv::CoreTLSData* data = cv::getCoreTlsData().get(); if (data->useTegra < 0) { @@ -1279,7 +1281,7 @@ bool useTegra() void setUseTegra(bool flag) { - CoreTLSData* data = getCoreTlsData().get(); + cv::CoreTLSData* data = cv::getCoreTlsData().get(); data->useTegra = flag; } @@ -1287,12 +1289,14 @@ void setUseTegra(bool flag) #endif +namespace cv { + void setOptimizations(bool enabled) { - cv::ipp::setUseIPP(enabled); - cv::ocl::setUseOpenCL(enabled); + ipp::setUseIPP(enabled); + ocl::setUseOpenCL(enabled); #ifdef HAVE_TEGRA_OPTIMIZATION - cv::tegra::setUseTegra(enabled); + ::tegra::setUseTegra(enabled); #endif } diff --git a/modules/features2d/src/fast.cpp b/modules/features2d/src/fast.cpp index b82572bbeb..11c039a0cc 100644 --- a/modules/features2d/src/fast.cpp +++ b/modules/features2d/src/fast.cpp @@ -346,7 +346,7 @@ void FAST(InputArray _img, std::vector& keypoints, int threshold, bool break; case FastFeatureDetector::TYPE_9_16: #ifdef HAVE_TEGRA_OPTIMIZATION - if(cv::tegra::useTegra() && tegra::FAST(_img, keypoints, threshold, nonmax_suppression)) + if(tegra::useTegra() && tegra::FAST(_img, keypoints, threshold, nonmax_suppression)) break; #endif FAST_t<16>(_img, keypoints, threshold, nonmax_suppression); diff --git a/modules/imgproc/src/canny.cpp b/modules/imgproc/src/canny.cpp index 2bc9de426e..8893be8839 100644 --- a/modules/imgproc/src/canny.cpp +++ b/modules/imgproc/src/canny.cpp @@ -261,7 +261,7 @@ void cv::Canny( InputArray _src, OutputArray _dst, Mat src = _src.getMat(), dst = _dst.getMat(); #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::canny(src, dst, low_thresh, high_thresh, aperture_size, L2gradient)) + if (tegra::useTegra() && tegra::canny(src, dst, low_thresh, high_thresh, aperture_size, L2gradient)) return; #endif diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp index c464e8234a..f8bc095891 100644 --- a/modules/imgproc/src/color.cpp +++ b/modules/imgproc/src/color.cpp @@ -6128,7 +6128,7 @@ struct YUV420sp2RGB888Invoker : ParallelLoopBody const uchar* y1 = my1 + rangeBegin * stride, *uv = muv + rangeBegin * stride / 2; #ifdef HAVE_TEGRA_OPTIMIZATION - if(cv::tegra::useTegra() && tegra::cvtYUV4202RGB(bIdx, uIdx, 3, y1, uv, stride, dst->ptr(rangeBegin), dst->step, rangeEnd - rangeBegin, dst->cols)) + if(tegra::useTegra() && tegra::cvtYUV4202RGB(bIdx, uIdx, 3, y1, uv, stride, dst->ptr(rangeBegin), dst->step, rangeEnd - rangeBegin, dst->cols)) return; #endif @@ -6197,7 +6197,7 @@ struct YUV420sp2RGBA8888Invoker : ParallelLoopBody const uchar* y1 = my1 + rangeBegin * stride, *uv = muv + rangeBegin * stride / 2; #ifdef HAVE_TEGRA_OPTIMIZATION - if(cv::tegra::useTegra() && tegra::cvtYUV4202RGB(bIdx, uIdx, 4, y1, uv, stride, dst->ptr(rangeBegin), dst->step, rangeEnd - rangeBegin, dst->cols)) + if(tegra::useTegra() && tegra::cvtYUV4202RGB(bIdx, uIdx, 4, y1, uv, stride, dst->ptr(rangeBegin), dst->step, rangeEnd - rangeBegin, dst->cols)) return; #endif @@ -7418,7 +7418,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) if( depth == CV_8U ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if(cv::tegra::useTegra() && tegra::cvtBGR2RGB(src, dst, bidx)) + if(tegra::useTegra() && tegra::cvtBGR2RGB(src, dst, bidx)) break; #endif CvtColorLoop(src, dst, RGB2RGB(scn, dcn, bidx)); @@ -7486,7 +7486,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) #ifdef HAVE_TEGRA_OPTIMIZATION if(code == CV_BGR2BGR565 || code == CV_BGRA2BGR565 || code == CV_RGB2BGR565 || code == CV_RGBA2BGR565) - if(cv::tegra::useTegra() && tegra::cvtRGB2RGB565(src, dst, code == CV_RGB2BGR565 || code == CV_RGBA2BGR565 ? 0 : 2)) + if(tegra::useTegra() && tegra::cvtRGB2RGB565(src, dst, code == CV_RGB2BGR565 || code == CV_RGBA2BGR565 ? 0 : 2)) break; #endif @@ -7612,7 +7612,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) if( depth == CV_8U ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if(cv::tegra::useTegra() && tegra::cvtRGB2Gray(src, dst, bidx)) + if(tegra::useTegra() && tegra::cvtRGB2Gray(src, dst, bidx)) break; #endif CvtColorLoop(src, dst, RGB2Gray(scn, bidx, 0)); @@ -7665,7 +7665,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) if( depth == CV_8U ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if(cv::tegra::useTegra() && tegra::cvtGray2RGB(src, dst)) + if(tegra::useTegra() && tegra::cvtGray2RGB(src, dst)) break; #endif CvtColorLoop(src, dst, Gray2RGB(dcn)); @@ -7745,7 +7745,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) if( depth == CV_8U ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if((code == CV_RGB2YCrCb || code == CV_BGR2YCrCb) && cv::tegra::useTegra() && tegra::cvtRGB2YCrCb(src, dst, bidx)) + if((code == CV_RGB2YCrCb || code == CV_BGR2YCrCb) && tegra::useTegra() && tegra::cvtRGB2YCrCb(src, dst, bidx)) break; #endif CvtColorLoop(src, dst, RGB2YCrCb_i(scn, bidx, coeffs_i)); @@ -8039,7 +8039,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) code == CV_BGR2HSV_FULL || code == CV_RGB2HSV_FULL ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if(cv::tegra::useTegra() && tegra::cvtRGB2HSV(src, dst, bidx, hrange)) + if(tegra::useTegra() && tegra::cvtRGB2HSV(src, dst, bidx, hrange)) break; #endif if( depth == CV_8U ) diff --git a/modules/imgproc/src/corner.cpp b/modules/imgproc/src/corner.cpp index a5d2442efe..38f9676007 100644 --- a/modules/imgproc/src/corner.cpp +++ b/modules/imgproc/src/corner.cpp @@ -269,7 +269,7 @@ cornerEigenValsVecs( const Mat& src, Mat& eigenv, int block_size, int borderType=BORDER_DEFAULT ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::cornerEigenValsVecs(src, eigenv, block_size, aperture_size, op_type, k, borderType)) + if (tegra::useTegra() && tegra::cornerEigenValsVecs(src, eigenv, block_size, aperture_size, op_type, k, borderType)) return; #endif #if CV_SSE2 diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index ef28441d05..d1e3a0b129 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -562,7 +562,7 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, _dst.create( _src.size(), dtype ); #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && scale == 1.0 && delta == 0) + if (tegra::useTegra() && scale == 1.0 && delta == 0) { Mat src = _src.getMat(), dst = _dst.getMat(); if (ksize == 3 && tegra::sobel3x3(src, dst, dx, dy, borderType)) @@ -620,7 +620,7 @@ void cv::Scharr( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, _dst.create( _src.size(), dtype ); #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && scale == 1.0 && delta == 0) + if (tegra::useTegra() && scale == 1.0 && delta == 0) { Mat src = _src.getMat(), dst = _dst.getMat(); if (tegra::scharr(src, dst, dx, dy, borderType)) @@ -873,7 +873,7 @@ void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize, #endif #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && scale == 1.0 && delta == 0) + if (tegra::useTegra() && scale == 1.0 && delta == 0) { Mat src = _src.getMat(), dst = _dst.getMat(); if (ksize == 1 && tegra::laplace1(src, dst, borderType)) diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 700ec68170..fb43eee0a1 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -4659,7 +4659,7 @@ void cv::filter2D( InputArray _src, OutputArray _dst, int ddepth, #endif #ifdef HAVE_TEGRA_OPTIMIZATION - if( cv::tegra::useTegra() && tegra::filter2D(src, dst, kernel, anchor, delta, borderType) ) + if( tegra::useTegra() && tegra::filter2D(src, dst, kernel, anchor, delta, borderType) ) return; #endif diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index 511fc5aea5..79ab3eca21 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -3227,7 +3227,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize, Mat dst = _dst.getMat(); #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::resize(src, dst, (float)inv_scale_x, (float)inv_scale_y, interpolation)) + if (tegra::useTegra() && tegra::resize(src, dst, (float)inv_scale_x, (float)inv_scale_y, interpolation)) return; #endif @@ -5572,7 +5572,7 @@ void cv::warpAffine( InputArray _src, OutputArray _dst, M0.convertTo(matM, matM.type()); #ifdef HAVE_TEGRA_OPTIMIZATION - if( cv::tegra::useTegra() && tegra::warpAffine(src, dst, M, flags, borderType, borderValue) ) + if( tegra::useTegra() && tegra::warpAffine(src, dst, M, flags, borderType, borderValue) ) return; #endif @@ -6098,7 +6098,7 @@ void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0, M0.convertTo(matM, matM.type()); #ifdef HAVE_TEGRA_OPTIMIZATION - if( cv::tegra::useTegra() && tegra::warpPerspective(src, dst, M, flags, borderType, borderValue) ) + if( tegra::useTegra() && tegra::warpPerspective(src, dst, M, flags, borderType, borderValue) ) return; #endif diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index c45c33429c..4018e08f70 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -1180,7 +1180,7 @@ void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borde int depth = src.depth(); #ifdef HAVE_TEGRA_OPTIMIZATION - if(borderType == BORDER_DEFAULT && cv::tegra::useTegra() && tegra::pyrDown(src, dst)) + if(borderType == BORDER_DEFAULT && tegra::useTegra() && tegra::pyrDown(src, dst)) return; #endif @@ -1257,7 +1257,7 @@ void cv::pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int borderT int depth = src.depth(); #ifdef HAVE_TEGRA_OPTIMIZATION - if(borderType == BORDER_DEFAULT && cv::tegra::useTegra() && tegra::pyrUp(src, dst)) + if(borderType == BORDER_DEFAULT && tegra::useTegra() && tegra::pyrUp(src, dst)) return; #endif diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index b901314095..53cd8269ce 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1324,7 +1324,7 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, ksize.width = 1; } #ifdef HAVE_TEGRA_OPTIMIZATION - if ( cv::tegra::useTegra() && tegra::box(src, dst, ksize, anchor, normalize, borderType) ) + if ( tegra::useTegra() && tegra::box(src, dst, ksize, anchor, normalize, borderType) ) return; #endif @@ -1650,7 +1650,7 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, #ifdef HAVE_TEGRA_OPTIMIZATION Mat src = _src.getMat(); Mat dst = _dst.getMat(); - if(sigma1 == 0 && sigma2 == 0 && cv::tegra::useTegra() && tegra::gaussian(src, dst, ksize, borderType)) + if(sigma1 == 0 && sigma2 == 0 && tegra::useTegra() && tegra::gaussian(src, dst, ksize, borderType)) return; #endif @@ -2698,7 +2698,7 @@ void cv::medianBlur( InputArray _src0, OutputArray _dst, int ksize ) #endif #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::medianBlur(src0, dst, ksize)) + if (tegra::useTegra() && tegra::medianBlur(src0, dst, ksize)) return; #endif diff --git a/modules/imgproc/src/templmatch.cpp b/modules/imgproc/src/templmatch.cpp index 726ec53f7b..c3d583bcca 100644 --- a/modules/imgproc/src/templmatch.cpp +++ b/modules/imgproc/src/templmatch.cpp @@ -933,7 +933,7 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result, Mat result = _result.getMat(); #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::matchTemplate(img, templ, result, method)) + if (tegra::useTegra() && tegra::matchTemplate(img, templ, result, method)) return; #endif diff --git a/modules/imgproc/src/thresh.cpp b/modules/imgproc/src/thresh.cpp index 8ef7fef8be..490bdff3e5 100644 --- a/modules/imgproc/src/thresh.cpp +++ b/modules/imgproc/src/thresh.cpp @@ -64,7 +64,7 @@ thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type ) } #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::thresh_8u(_src, _dst, roi.width, roi.height, thresh, maxval, type)) + if (tegra::useTegra() && tegra::thresh_8u(_src, _dst, roi.width, roi.height, thresh, maxval, type)) return; #endif @@ -408,7 +408,7 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type ) } #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::thresh_16s(_src, _dst, roi.width, roi.height, thresh, maxval, type)) + if (tegra::useTegra() && tegra::thresh_16s(_src, _dst, roi.width, roi.height, thresh, maxval, type)) return; #endif @@ -676,7 +676,7 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type ) } #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::thresh_32f(_src, _dst, roi.width, roi.height, thresh, maxval, type)) + if (tegra::useTegra() && tegra::thresh_32f(_src, _dst, roi.width, roi.height, thresh, maxval, type)) return; #endif diff --git a/modules/objdetect/src/cascadedetect.cpp b/modules/objdetect/src/cascadedetect.cpp index 01f83d3d8c..1c0bbf1b0b 100644 --- a/modules/objdetect/src/cascadedetect.cpp +++ b/modules/objdetect/src/cascadedetect.cpp @@ -937,11 +937,10 @@ Ptr CascadeClassifierImpl::getMaskGenerato Ptr createFaceDetectionMaskGenerator() { #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra()) + if (tegra::useTegra()) return tegra::getCascadeClassifierMaskGenerator(); -#else - return Ptr(); #endif + return Ptr(); } class CascadeClassifierInvoker : public ParallelLoopBody diff --git a/modules/photo/src/denoising.cpp b/modules/photo/src/denoising.cpp index 90b76a8ec7..b4767a738d 100644 --- a/modules/photo/src/denoising.cpp +++ b/modules/photo/src/denoising.cpp @@ -58,7 +58,7 @@ void cv::fastNlMeansDenoising( InputArray _src, OutputArray _dst, float h, Mat dst = _dst.getMat(); #ifdef HAVE_TEGRA_OPTIMIZATION - if(cv::tegra::useTegra() && tegra::fastNlMeansDenoising(src, dst, h, templateWindowSize, searchWindowSize)) + if(tegra::useTegra() && tegra::fastNlMeansDenoising(src, dst, h, templateWindowSize, searchWindowSize)) return; #endif diff --git a/modules/stitching/src/blenders.cpp b/modules/stitching/src/blenders.cpp index 7be914be86..82e65fa388 100644 --- a/modules/stitching/src/blenders.cpp +++ b/modules/stitching/src/blenders.cpp @@ -481,7 +481,7 @@ void normalizeUsingWeightMap(InputArray _weight, InputOutputArray _src) #ifdef HAVE_TEGRA_OPTIMIZATION src = _src.getMat(); weight = _weight.getMat(); - if(cv::tegra::useTegra() && tegra::normalizeUsingWeightMap(weight, src)) + if(tegra::useTegra() && tegra::normalizeUsingWeightMap(weight, src)) return; #endif @@ -552,7 +552,7 @@ void createLaplacePyr(InputArray img, int num_levels, std::vector &pyr) { #ifdef HAVE_TEGRA_OPTIMIZATION cv::Mat imgMat = img.getMat(); - if(cv::tegra::useTegra() && tegra::createLaplacePyr(imgMat, num_levels, pyr)) + if(tegra::useTegra() && tegra::createLaplacePyr(imgMat, num_levels, pyr)) return; #endif diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index 43669b2544..2587da914c 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -148,7 +148,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat CV_Assert(features2.descriptors.depth() == CV_8U || features2.descriptors.depth() == CV_32F); #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::match2nearest(features1, features2, matches_info, match_conf_)) + if (tegra::useTegra() && tegra::match2nearest(features1, features2, matches_info, match_conf_)) return; #endif diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index f40b38237f..f5fed678d5 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -3068,7 +3068,7 @@ void printVersionInfo(bool useStdOut) if (useStdOut) std::cout << "CPU features: " << cpu_features << std::endl; #ifdef HAVE_TEGRA_OPTIMIZATION - const char * tegra_optimization = cv::tegra::useTegra() && tegra::isDeviceSupported() ? "enabled" : "disabled"; + const char * tegra_optimization = tegra::useTegra() && tegra::isDeviceSupported() ? "enabled" : "disabled"; ::testing::Test::RecordProperty("cv_tegra_optimization", tegra_optimization); if (useStdOut) std::cout << "Tegra optimization: " << tegra_optimization << std::endl; #endif diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index 22b65dfbda..43dde7df78 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -58,7 +58,7 @@ static void calcSharrDeriv(const cv::Mat& src, cv::Mat& dst) dst.create(rows, cols, CV_MAKETYPE(DataType::depth, cn*2)); #ifdef HAVE_TEGRA_OPTIMIZATION - if (cv::tegra::useTegra() && tegra::calcSharrDeriv(src, dst)) + if (tegra::useTegra() && tegra::calcSharrDeriv(src, dst)) return; #endif From c10f1851cb32d6f6253c4a42ec3cc286684a2389 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 27 Feb 2015 12:52:28 +0300 Subject: [PATCH 7/9] rename setOptimizations -> setUseOptimizations --- modules/core/include/opencv2/core/base.hpp | 2 +- modules/core/src/system.cpp | 2 +- modules/ts/include/opencv2/ts/cuda_test.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index 6ab3e75b70..8559fc2397 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -727,7 +727,7 @@ CV_EXPORTS void setUseIPP(bool flag); } // ipp -CV_EXPORTS void setOptimizations(bool enabled); +CV_EXPORTS void setUseOptimizations(bool enabled); //! @endcond diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 74d73c44e5..6152cbe702 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1291,7 +1291,7 @@ void setUseTegra(bool flag) namespace cv { -void setOptimizations(bool enabled) +void setUseOptimizations(bool enabled) { ipp::setUseIPP(enabled); ocl::setUseOpenCL(enabled); diff --git a/modules/ts/include/opencv2/ts/cuda_test.hpp b/modules/ts/include/opencv2/ts/cuda_test.hpp index 2f4ee6936e..d1e1e9db73 100644 --- a/modules/ts/include/opencv2/ts/cuda_test.hpp +++ b/modules/ts/include/opencv2/ts/cuda_test.hpp @@ -352,7 +352,7 @@ namespace cv { namespace cuda #ifdef HAVE_CUDA #define CV_CUDA_TEST_MAIN(resourcesubdir) \ - CV_TEST_MAIN(resourcesubdir, cvtest::parseCudaDeviceOptions(argc, argv), cvtest::printCudaInfo(), cv::setOptimizations(false)) + CV_TEST_MAIN(resourcesubdir, cvtest::parseCudaDeviceOptions(argc, argv), cvtest::printCudaInfo(), cv::setUseOptimizations(false)) #else // HAVE_CUDA From 4800a34be34d3c8e6972b1be8ad30b0aabd8d079 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 27 Feb 2015 12:52:44 +0300 Subject: [PATCH 8/9] do not dump OpenCL info if it is disabled --- modules/ts/src/ocl_test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/ts/src/ocl_test.cpp b/modules/ts/src/ocl_test.cpp index 270dec9145..69d10aac0d 100644 --- a/modules/ts/src/ocl_test.cpp +++ b/modules/ts/src/ocl_test.cpp @@ -98,6 +98,13 @@ void dumpOpenCLDevice() try { + if (!useOpenCL()) + { + DUMP_MESSAGE_STDOUT("OpenCL is disabled"); + DUMP_PROPERTY_XML("cv_ocl", "disabled"); + return; + } + std::vector platforms; cv::ocl::getPlatfomsInfo(platforms); if (platforms.size() > 0) From 4254e35f6afea7d2f186020e54c0e937c9e3e72b Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 27 Feb 2015 14:24:51 +0300 Subject: [PATCH 9/9] merge new setUseOptimizations function with existed setUseOptimized --- modules/core/include/opencv2/core/base.hpp | 2 -- modules/core/src/system.cpp | 19 ++++++------------- modules/ts/include/opencv2/ts/cuda_test.hpp | 2 +- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index 8559fc2397..f2acaa3fb4 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -727,8 +727,6 @@ CV_EXPORTS void setUseIPP(bool flag); } // ipp -CV_EXPORTS void setUseOptimizations(bool enabled); - //! @endcond //! @} core_utils diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 6152cbe702..c67a78745d 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -385,6 +385,12 @@ void setUseOptimized( bool flag ) useOptimizedFlag = flag; currentFeatures = flag ? &featuresEnabled : &featuresDisabled; USE_SSE2 = currentFeatures->have[CV_CPU_SSE2]; + + ipp::setUseIPP(flag); + ocl::setUseOpenCL(flag); +#ifdef HAVE_TEGRA_OPTIMIZATION + ::tegra::setUseTegra(flag); +#endif } bool useOptimized(void) @@ -1289,17 +1295,4 @@ void setUseTegra(bool flag) #endif -namespace cv { - -void setUseOptimizations(bool enabled) -{ - ipp::setUseIPP(enabled); - ocl::setUseOpenCL(enabled); -#ifdef HAVE_TEGRA_OPTIMIZATION - ::tegra::setUseTegra(enabled); -#endif -} - -} // namespace cv - /* End of file. */ diff --git a/modules/ts/include/opencv2/ts/cuda_test.hpp b/modules/ts/include/opencv2/ts/cuda_test.hpp index d1e1e9db73..8783fb6412 100644 --- a/modules/ts/include/opencv2/ts/cuda_test.hpp +++ b/modules/ts/include/opencv2/ts/cuda_test.hpp @@ -352,7 +352,7 @@ namespace cv { namespace cuda #ifdef HAVE_CUDA #define CV_CUDA_TEST_MAIN(resourcesubdir) \ - CV_TEST_MAIN(resourcesubdir, cvtest::parseCudaDeviceOptions(argc, argv), cvtest::printCudaInfo(), cv::setUseOptimizations(false)) + CV_TEST_MAIN(resourcesubdir, cvtest::parseCudaDeviceOptions(argc, argv), cvtest::printCudaInfo(), cv::setUseOptimized(false)) #else // HAVE_CUDA