From 1388826c416da68d5cabf1e3b25339123e8c6943 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Fri, 20 May 2011 14:33:41 +0000 Subject: [PATCH] Tegra optimization for calcOpticalFlowPyrLK --- modules/highgui/src/cap_android.cpp | 16 ++++++++-------- modules/video/src/lkpyramid.cpp | 5 +++++ modules/video/src/precomp.hpp | 4 ++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/modules/highgui/src/cap_android.cpp b/modules/highgui/src/cap_android.cpp index 4a0fb77094..2467d1b458 100644 --- a/modules/highgui/src/cap_android.cpp +++ b/modules/highgui/src/cap_android.cpp @@ -459,7 +459,6 @@ bool CvCapture_Android::convertYUV420i2Grey(int width, int height, const unsigne return !resmat.empty(); } -#ifndef HAVE_TEGRA_OPTIMIZATION template struct YUV420i2BGR888Invoker { @@ -516,7 +515,6 @@ struct YUV420i2BGR888Invoker } } }; -#endif bool CvCapture_Android::convertYUV420i2BGR888(int width, int height, const unsigned char* yuv, cv::Mat& resmat, bool inRGBorder) { @@ -529,13 +527,15 @@ bool CvCapture_Android::convertYUV420i2BGR888(int width, int height, const unsig unsigned char* uv = y1 + width * height; #ifdef HAVE_TEGRA_OPTIMIZATION - cv::parallel_for(cv::BlockedRange(0, height, 2), tegra::YUV420i2BGR888Invoker(resmat, width, y1, uv, inRGBorder)); -#else - if (inRGBorder) - cv::parallel_for(cv::BlockedRange(0, height, 2), YUV420i2BGR888Invoker<2>(resmat, width, y1, uv)); - else - cv::parallel_for(cv::BlockedRange(0, height, 2), YUV420i2BGR888Invoker<0>(resmat, width, y1, uv)); +#warning "TEGRA OPTIMIZED YUV420i TO RGB888 CONVERSION IS USED" + if (!tegra::YUV420i2BGR888(width, height, y1, uv, resmat, inRGBorder)) #endif + { + if (inRGBorder) + cv::parallel_for(cv::BlockedRange(0, height, 2), YUV420i2BGR888Invoker<2>(resmat, width, y1, uv)); + else + cv::parallel_for(cv::BlockedRange(0, height, 2), YUV420i2BGR888Invoker<0>(resmat, width, y1, uv)); + } return !resmat.empty(); } diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index 3d5d9a4438..5ab9cd508a 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -50,6 +50,11 @@ void cv::calcOpticalFlowPyrLK( const InputArray& _prevImg, const InputArray& _ne double derivLambda, int flags ) { +#ifdef HAVE_TEGRA_OPTIMIZATION +#warning "TEGRA OPTIMIZED calcOpticalFlowPyrLK IS USED" + if (tegra::calcOpticalFlowPyrLK(_prevImg, _nextImg, _prevPts, _nextPts, _status, _err, winSize, maxLevel, criteria, derivLambda, flags)) + return; +#endif Mat prevImg = _prevImg.getMat(), nextImg = _nextImg.getMat(), prevPtsMat = _prevPts.getMat(); derivLambda = std::min(std::max(derivLambda, 0.), 1.); double lambda1 = 1. - derivLambda, lambda2 = derivLambda; diff --git a/modules/video/src/precomp.hpp b/modules/video/src/precomp.hpp index 0e3ac9de4f..98c10e8cd4 100644 --- a/modules/video/src/precomp.hpp +++ b/modules/video/src/precomp.hpp @@ -56,4 +56,8 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/core/internal.hpp" +#ifdef HAVE_TEGRA_OPTIMIZATION +#include "opencv2/video/video_tegra.hpp" +#endif + #endif