1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16 // Third party copyrights are property of their respective owners.
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
21 // * Redistribution's of source code must retain the above copyright notice,
22 // this list of conditions and the following disclaimer.
24 // * Redistribution's in binary form must reproduce the above copyright notice,
25 // this list of conditions and the following disclaimer in the documentation
26 // and/or other materials provided with the distribution.
28 // * The name of the copyright holders may not be used to endorse or promote products
29 // derived from this software without specific prior written permission.
31 // This software is provided by the copyright holders and contributors "as is" and
32 // any express or implied warranties, including, but not limited to, the implied
33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
34 // In no event shall the Intel Corporation or contributors be liable for any direct,
35 // indirect, incidental, special, exemplary, or consequential damages
36 // (including, but not limited to, procurement of substitute goods or services;
37 // loss of use, data, or profits; or business interruption) however caused
38 // and on any theory of liability, whether in contract, strict liability,
39 // or tort (including negligence or otherwise) arising in any way out of
40 // the use of this software, even if advised of the possibility of such damage.
44 #ifndef __OPENCV_TRACKING_HPP__
45 #define __OPENCV_TRACKING_HPP__
47 #include "opencv2/core.hpp"
48 #include "opencv2/imgproc.hpp"
53 enum { OPTFLOW_USE_INITIAL_FLOW = 4,
54 OPTFLOW_LK_GET_MIN_EIGENVALS = 8,
55 OPTFLOW_FARNEBACK_GAUSSIAN = 256
58 //! updates the object tracking window using CAMSHIFT algorithm
59 CV_EXPORTS_W RotatedRect CamShift( InputArray probImage, CV_IN_OUT Rect& window,
60 TermCriteria criteria );
62 //! updates the object tracking window using meanshift algorithm
63 CV_EXPORTS_W int meanShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria );
65 //! constructs a pyramid which can be used as input for calcOpticalFlowPyrLK
66 CV_EXPORTS_W int buildOpticalFlowPyramid( InputArray img, OutputArrayOfArrays pyramid,
67 Size winSize, int maxLevel, bool withDerivatives = true,
68 int pyrBorder = BORDER_REFLECT_101,
69 int derivBorder = BORDER_CONSTANT,
70 bool tryReuseInputImage = true );
72 //! computes sparse optical flow using multi-scale Lucas-Kanade algorithm
73 CV_EXPORTS_W void calcOpticalFlowPyrLK( InputArray prevImg, InputArray nextImg,
74 InputArray prevPts, InputOutputArray nextPts,
75 OutputArray status, OutputArray err,
76 Size winSize = Size(21,21), int maxLevel = 3,
77 TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01),
78 int flags = 0, double minEigThreshold = 1e-4 );
80 //! computes dense optical flow using Farneback algorithm
81 CV_EXPORTS_W void calcOpticalFlowFarneback( InputArray prev, InputArray next, InputOutputArray flow,
82 double pyr_scale, int levels, int winsize,
83 int iterations, int poly_n, double poly_sigma,
86 //! estimates the best-fit Euqcidean, similarity, affine or perspective transformation
87 // that maps one 2D point set to another or one image to another.
88 CV_EXPORTS_W Mat estimateRigidTransform( InputArray src, InputArray dst, bool fullAffine );
93 MOTION_TRANSLATION = 0,
99 //! estimates the best-fit Translation, Euclidean, Affine or Perspective Transformation
100 // with respect to Enhanced Correlation Coefficient criterion that maps one image to
101 // another (area-based alignment)
104 // Evangelidis, G. E., Psarakis, E.Z., Parametric Image Alignment using
105 // Enhanced Correlation Coefficient Maximization, PAMI, 30(8), 2008
106 CV_EXPORTS_W double findTransformECC( InputArray templateImage, InputArray inputImage,
107 InputOutputArray warpMatrix, int motionType = MOTION_AFFINE,
108 TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001));
113 The class implements standard Kalman filter \url{http://en.wikipedia.org/wiki/Kalman_filter}.
114 However, you can modify KalmanFilter::transitionMatrix, KalmanFilter::controlMatrix and
115 KalmanFilter::measurementMatrix to get the extended Kalman filter functionality.
117 class CV_EXPORTS_W KalmanFilter
120 //! the default constructor
121 CV_WRAP KalmanFilter();
122 //! the full constructor taking the dimensionality of the state, of the measurement and of the control vector
123 CV_WRAP KalmanFilter( int dynamParams, int measureParams, int controlParams = 0, int type = CV_32F );
124 //! re-initializes Kalman filter. The previous content is destroyed.
125 void init( int dynamParams, int measureParams, int controlParams = 0, int type = CV_32F );
127 //! computes predicted state
128 CV_WRAP const Mat& predict( const Mat& control = Mat() );
129 //! updates the predicted state from the measurement
130 CV_WRAP const Mat& correct( const Mat& measurement );
132 //! sets predicted state
133 CV_WRAP void setStatePre( const Mat& state ) { statePre = state; }
134 //! sets corrected state
135 CV_WRAP void setStatePost( const Mat& state ) { statePost = state; }
136 //! sets transition matrix
137 CV_WRAP void setTransitionMatrix( const Mat& transition ) { transitionMatrix = transition; }
138 //! sets control matrix
139 CV_WRAP void setControlMatrix( const Mat& control ) { controlMatrix = control; }
140 //! sets measurement matrix
141 CV_WRAP void setMeasurementMatrix( const Mat& measurement ) { measurementMatrix = measurement; }
142 //! sets process noise covariance matrix
143 CV_WRAP void setProcessNoiseCov( const Mat& noise ) { processNoiseCov = noise; }
144 //! sets measurement noise covariance matrix
145 CV_WRAP void setMeasurementNoiseCov( const Mat& noise ) { measurementNoiseCov = noise; }
146 //! sets posteriori error covariance
147 CV_WRAP void setErrorCovPost( const Mat& error ) { errorCovPost = error; }
149 Mat statePre; //!< predicted state (x'(k)): x(k)=A*x(k-1)+B*u(k)
150 Mat statePost; //!< corrected state (x(k)): x(k)=x'(k)+K(k)*(z(k)-H*x'(k))
151 Mat transitionMatrix; //!< state transition matrix (A)
152 Mat controlMatrix; //!< control matrix (B) (not used if there is no control)
153 Mat measurementMatrix; //!< measurement matrix (H)
154 Mat processNoiseCov; //!< process noise covariance matrix (Q)
155 Mat measurementNoiseCov;//!< measurement noise covariance matrix (R)
156 Mat errorCovPre; //!< priori error estimate covariance matrix (P'(k)): P'(k)=A*P(k-1)*At + Q)*/
157 Mat gain; //!< Kalman gain matrix (K(k)): K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)
158 Mat errorCovPost; //!< posteriori error estimate covariance matrix (P(k)): P(k)=(I-K(k)*H)*P'(k)
160 // temporary matrices
170 class CV_EXPORTS_W DenseOpticalFlow : public Algorithm
173 CV_WRAP virtual void calc( InputArray I0, InputArray I1, InputOutputArray flow ) = 0;
174 CV_WRAP virtual void collectGarbage() = 0;
177 // Implementation of the Zach, Pock and Bischof Dual TV-L1 Optical Flow method
180 // [1] C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow".
181 // [2] Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation".
182 CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_DualTVL1();