From 1417dc65f78991714761f381510b4fb064d9d5ac Mon Sep 17 00:00:00 2001 From: Vladislav Samsonov Date: Sat, 21 May 2016 20:21:57 +0300 Subject: [PATCH] Boosted accuracy a little bit more --- .../optflow/include/opencv2/optflow/pcaflow.hpp | 4 +++- modules/optflow/src/pcaflow.cpp | 17 ++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/optflow/include/opencv2/optflow/pcaflow.hpp b/modules/optflow/include/opencv2/optflow/pcaflow.hpp index c8af8e367..8f6dda290 100644 --- a/modules/optflow/include/opencv2/optflow/pcaflow.hpp +++ b/modules/optflow/include/opencv2/optflow/pcaflow.hpp @@ -172,10 +172,12 @@ protected: const float sparseRate; // (0 .. 0.1) const float retainedCornersFraction; // [0 .. 1] const float occlusionsThreshold; + const float dampingFactor; public: OpticalFlowPCAFlow( const Size _basisSize = Size( 18, 14 ), float _sparseRate = 0.02, - float _retainedCornersFraction = 1.0, float _occlusionsThreshold = 0.00002 ); + float _retainedCornersFraction = 0.7, float _occlusionsThreshold = 0.0003, + float _dampingFactor = 0.00002 ); void calc( InputArray I0, InputArray I1, InputOutputArray flow ); void collectGarbage(); diff --git a/modules/optflow/src/pcaflow.cpp b/modules/optflow/src/pcaflow.cpp index 86a7da2ef..813c0cf5d 100644 --- a/modules/optflow/src/pcaflow.cpp +++ b/modules/optflow/src/pcaflow.cpp @@ -51,9 +51,9 @@ namespace optflow { OpticalFlowPCAFlow::OpticalFlowPCAFlow( const Size _basisSize, float _sparseRate, float _retainedCornersFraction, - float _occlusionsThreshold ) + float _occlusionsThreshold, float _dampingFactor ) : basisSize( _basisSize ), sparseRate( _sparseRate ), retainedCornersFraction( _retainedCornersFraction ), - occlusionsThreshold( _occlusionsThreshold ) + occlusionsThreshold( _occlusionsThreshold ), dampingFactor( _dampingFactor ) { CV_Assert( sparseRate > 0 && sparseRate <= 0.1 ); CV_Assert( retainedCornersFraction >= 0 && retainedCornersFraction <= 1.0 ); @@ -216,13 +216,13 @@ void OpticalFlowPCAFlow::removeOcclusions( Mat &from, Mat &to, std::vector features, predictedFeatures; findSparseFeatures( from, to, features, predictedFeatures ); @@ -337,7 +337,6 @@ void OpticalFlowPCAFlow::calc( InputArray I0, InputArray I1, InputOutputArray fl flowOut.create( size, CV_32FC2 ); Mat flow = flowOut.getMat(); - // interpolateSparseFlow(flow, features, predictedFeatures); // for ( size_t i = 0; i < features.size(); ++i ) // flow.at( features[i].y, features[i].x ) = /*Point2f(10,10);*/ predictedFeatures[i] - features[i]; @@ -345,8 +344,8 @@ void OpticalFlowPCAFlow::calc( InputArray I0, InputArray I1, InputOutputArray fl getSystem( A, b1, b2, features, predictedFeatures, size ); // solve( A1, b1, w1, DECOMP_CHOLESKY | DECOMP_NORMAL ); // solve( A2, b2, w2, DECOMP_CHOLESKY | DECOMP_NORMAL ); - solveLSQR( A, b1, w1, 0.00002 * size.area() ); - solveLSQR( A, b2, w2, 0.00002 * size.area() ); + solveLSQR( A, b1, w1, dampingFactor * size.area() ); + solveLSQR( A, b2, w2, dampingFactor * size.area() ); Mat flowSmall( basisSize * 16, CV_32FC2 ); reduceToFlow( w1, w2, flowSmall, basisSize ); resize( flowSmall, flow, size, 0, 0, INTER_LINEAR );