From 62f8240b004fe2d1386be8003082b42673fa7c55 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 31 Dec 2014 15:36:51 +0300 Subject: [PATCH] fix videostab module compilation --- .../opencv2/videostab/optical_flow.hpp | 4 +-- modules/videostab/src/optical_flow.cpp | 36 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/modules/videostab/include/opencv2/videostab/optical_flow.hpp b/modules/videostab/include/opencv2/videostab/optical_flow.hpp index a34a82e3f8..41d1953549 100644 --- a/modules/videostab/include/opencv2/videostab/optical_flow.hpp +++ b/modules/videostab/include/opencv2/videostab/optical_flow.hpp @@ -121,7 +121,7 @@ public: cuda::GpuMat &status); private: - cuda::PyrLKOpticalFlow optFlowEstimator_; + Ptr optFlowEstimator_; cuda::GpuMat frame0_, frame1_, points0_, points1_, status_, errors_; }; @@ -136,7 +136,7 @@ public: OutputArray errors); private: - cuda::PyrLKOpticalFlow optFlowEstimator_; + Ptr optFlowEstimator_; cuda::GpuMat frame0_, frame1_, flowX_, flowY_, errors_; }; diff --git a/modules/videostab/src/optical_flow.cpp b/modules/videostab/src/optical_flow.cpp index d8a059c1fd..32c8133a7d 100644 --- a/modules/videostab/src/optical_flow.cpp +++ b/modules/videostab/src/optical_flow.cpp @@ -45,6 +45,10 @@ #include "opencv2/videostab/optical_flow.hpp" #include "opencv2/videostab/ring_buffer.hpp" +#ifdef HAVE_OPENCV_CUDAARITHM + #include "opencv2/cudaarithm.hpp" +#endif + namespace cv { namespace videostab @@ -63,6 +67,7 @@ void SparsePyrLkOptFlowEstimator::run( SparsePyrLkOptFlowEstimatorGpu::SparsePyrLkOptFlowEstimatorGpu() { CV_Assert(cuda::getCudaEnabledDeviceCount() > 0); + optFlowEstimator_ = cuda::SparsePyrLKOpticalFlow::create(); } @@ -91,9 +96,9 @@ void SparsePyrLkOptFlowEstimatorGpu::run( const cuda::GpuMat &frame0, const cuda::GpuMat &frame1, const cuda::GpuMat &points0, cuda::GpuMat &points1, cuda::GpuMat &status, cuda::GpuMat &errors) { - optFlowEstimator_.winSize = winSize_; - optFlowEstimator_.maxLevel = maxLevel_; - optFlowEstimator_.sparse(frame0, frame1, points0, points1, status, &errors); + optFlowEstimator_->setWinSize(winSize_); + optFlowEstimator_->setMaxLevel(maxLevel_); + optFlowEstimator_->calc(frame0, frame1, points0, points1, status, errors); } @@ -101,15 +106,16 @@ void SparsePyrLkOptFlowEstimatorGpu::run( const cuda::GpuMat &frame0, const cuda::GpuMat &frame1, const cuda::GpuMat &points0, cuda::GpuMat &points1, cuda::GpuMat &status) { - optFlowEstimator_.winSize = winSize_; - optFlowEstimator_.maxLevel = maxLevel_; - optFlowEstimator_.sparse(frame0, frame1, points0, points1, status); + optFlowEstimator_->setWinSize(winSize_); + optFlowEstimator_->setMaxLevel(maxLevel_); + optFlowEstimator_->calc(frame0, frame1, points0, points1, status); } DensePyrLkOptFlowEstimatorGpu::DensePyrLkOptFlowEstimatorGpu() { CV_Assert(cuda::getCudaEnabledDeviceCount() > 0); + optFlowEstimator_ = cuda::DensePyrLKOpticalFlow::create(); } @@ -120,16 +126,24 @@ void DensePyrLkOptFlowEstimatorGpu::run( frame0_.upload(frame0.getMat()); frame1_.upload(frame1.getMat()); - optFlowEstimator_.winSize = winSize_; - optFlowEstimator_.maxLevel = maxLevel_; + optFlowEstimator_->setWinSize(winSize_); + optFlowEstimator_->setMaxLevel(maxLevel_); if (errors.needed()) { - optFlowEstimator_.dense(frame0_, frame1_, flowX_, flowY_, &errors_); - errors_.download(errors.getMatRef()); + CV_Error(Error::StsNotImplemented, "DensePyrLkOptFlowEstimatorGpu doesn't support errors calculation"); } else - optFlowEstimator_.dense(frame0_, frame1_, flowX_, flowY_); + { + cuda::GpuMat flow; + optFlowEstimator_->calc(frame0_, frame1_, flow); + + cuda::GpuMat flows[2]; + cuda::split(flow, flows); + + flowX_ = flows[0]; + flowY_ = flows[1]; + } flowX_.download(flowX.getMatRef()); flowY_.download(flowY.getMatRef());