diff --git a/modules/optflow/include/opencv2/optflow/pcaflow.hpp b/modules/optflow/include/opencv2/optflow/pcaflow.hpp index b0a205061..607d9597a 100644 --- a/modules/optflow/include/opencv2/optflow/pcaflow.hpp +++ b/modules/optflow/include/opencv2/optflow/pcaflow.hpp @@ -66,7 +66,7 @@ namespace optflow * Solution will be regularized according to this prior. * You need to generate appropriate prior file with "learn_prior.py" script beforehand. */ -class PCAPrior +class CV_EXPORTS_W PCAPrior { private: Mat L1; @@ -84,10 +84,10 @@ public: void fillConstraints( float *A1, float *A2, float *b1, float *b2 ) const; }; -class OpticalFlowPCAFlow : public DenseOpticalFlow +class CV_EXPORTS_W OpticalFlowPCAFlow : public DenseOpticalFlow { protected: - const PCAPrior *prior; + const Ptr prior; const Size basisSize; const float sparseRate; // (0 .. 0.1) const float retainedCornersFraction; // [0 .. 1] @@ -95,7 +95,7 @@ protected: const float dampingFactor; public: - OpticalFlowPCAFlow( const PCAPrior *_prior = 0, const Size _basisSize = Size( 18, 14 ), + OpticalFlowPCAFlow( Ptr _prior = Ptr(), const Size _basisSize = Size( 18, 14 ), float _sparseRate = 0.02, float _retainedCornersFraction = 0.7, float _occlusionsThreshold = 0.0003, float _dampingFactor = 0.00002 ); diff --git a/modules/optflow/samples/optical_flow_evaluation.cpp b/modules/optflow/samples/optical_flow_evaluation.cpp index 5cbeffec3..4cfc1f89e 100644 --- a/modules/optflow/samples/optical_flow_evaluation.cpp +++ b/modules/optflow/samples/optical_flow_evaluation.cpp @@ -17,7 +17,8 @@ const String keys = "{help h usage ? | | print this message }" "{m measure |endpoint| error measure - [endpoint or angular] }" "{r region |all | region to compute stats about [all, discontinuities, untextured] }" "{d display | | display additional info images (pauses program execution) }" - "{g gpu | | use OpenCL}"; + "{g gpu | | use OpenCL}" + "{prior | | path to a prior file for PCAFlow}"; inline bool isFlowCorrect( const Point2f u ) { @@ -258,8 +259,15 @@ int main( int argc, char** argv ) algorithm = createOptFlow_DeepFlow(); else if ( method == "sparsetodenseflow" ) algorithm = createOptFlow_SparseToDense(); - else if ( method == "pcaflow" ) - algorithm = createOptFlow_PCAFlow(); + else if ( method == "pcaflow" ) { + if ( parser.has("prior") ) { + String prior = parser.get("prior"); + printf("Using prior file: %s\n", prior.c_str()); + algorithm = makePtr(makePtr(prior.c_str())); + } + else + algorithm = createOptFlow_PCAFlow(); + } else if ( method == "DISflow" ) algorithm = createOptFlow_DIS(); else diff --git a/modules/optflow/src/pcaflow.cpp b/modules/optflow/src/pcaflow.cpp index 3db6bc27c..36ecf30fe 100644 --- a/modules/optflow/src/pcaflow.cpp +++ b/modules/optflow/src/pcaflow.cpp @@ -48,7 +48,7 @@ namespace cv namespace optflow { -OpticalFlowPCAFlow::OpticalFlowPCAFlow( const PCAPrior *_prior, const Size _basisSize, float _sparseRate, +OpticalFlowPCAFlow::OpticalFlowPCAFlow( Ptr _prior, const Size _basisSize, float _sparseRate, float _retainedCornersFraction, float _occlusionsThreshold, float _dampingFactor ) : prior( _prior ), basisSize( _basisSize ), sparseRate( _sparseRate ), @@ -451,7 +451,7 @@ void OpticalFlowPCAFlow::calc( InputArray I0, InputArray I1, InputOutputArray fl Mat flow = flowOut.getMat(); Mat w1, w2; - if ( prior ) + if ( prior.get() ) { Mat A1, A2, b1, b2; getSystem( A1, A2, b1, b2, features, predictedFeatures, size );