18a3088aefdbdbabdc9d4cdca771192f4d9dc7ed
[profile/ivi/opencv.git] / modules / video / include / opencv2 / video / tracking.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                          License Agreement
11 //                For Open Source Computer Vision Library
12 //
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.
17 //
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
20 //
21 //   * Redistribution's of source code must retain the above copyright notice,
22 //     this list of conditions and the following disclaimer.
23 //
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.
27 //
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.
30 //
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.
41 //
42 //M*/
43
44 #ifndef __OPENCV_TRACKING_HPP__
45 #define __OPENCV_TRACKING_HPP__
46
47 #include "opencv2/core.hpp"
48 #include "opencv2/imgproc.hpp"
49
50 namespace cv
51 {
52
53 enum { OPTFLOW_USE_INITIAL_FLOW     = 4,
54        OPTFLOW_LK_GET_MIN_EIGENVALS = 8,
55        OPTFLOW_FARNEBACK_GAUSSIAN   = 256
56      };
57
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 );
61
62 //! updates the object tracking window using meanshift algorithm
63 CV_EXPORTS_W int meanShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria );
64
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 );
71
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 );
79
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,
84                                             int flags );
85
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 );
89
90
91 enum
92 {
93     MOTION_TRANSLATION = 0,
94     MOTION_EUCLIDEAN   = 1,
95     MOTION_AFFINE      = 2,
96     MOTION_HOMOGRAPHY  = 3
97 };
98
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)
102 //
103 // see reference:
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));
109
110 /*!
111  Kalman filter.
112
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.
116 */
117 class CV_EXPORTS_W KalmanFilter
118 {
119 public:
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 );
126
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 );
131
132     Mat statePre;           //!< predicted state (x'(k)): x(k)=A*x(k-1)+B*u(k)
133     Mat statePost;          //!< corrected state (x(k)): x(k)=x'(k)+K(k)*(z(k)-H*x'(k))
134     Mat transitionMatrix;   //!< state transition matrix (A)
135     Mat controlMatrix;      //!< control matrix (B) (not used if there is no control)
136     Mat measurementMatrix;  //!< measurement matrix (H)
137     Mat processNoiseCov;    //!< process noise covariance matrix (Q)
138     Mat measurementNoiseCov;//!< measurement noise covariance matrix (R)
139     Mat errorCovPre;        //!< priori error estimate covariance matrix (P'(k)): P'(k)=A*P(k-1)*At + Q)*/
140     Mat gain;               //!< Kalman gain matrix (K(k)): K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)
141     Mat errorCovPost;       //!< posteriori error estimate covariance matrix (P(k)): P(k)=(I-K(k)*H)*P'(k)
142
143     // temporary matrices
144     Mat temp1;
145     Mat temp2;
146     Mat temp3;
147     Mat temp4;
148     Mat temp5;
149 };
150
151
152
153 class CV_EXPORTS_W DenseOpticalFlow : public Algorithm
154 {
155 public:
156     CV_WRAP virtual void calc( InputArray I0, InputArray I1, InputOutputArray flow ) = 0;
157     CV_WRAP virtual void collectGarbage() = 0;
158 };
159
160 // Implementation of the Zach, Pock and Bischof Dual TV-L1 Optical Flow method
161 //
162 // see reference:
163 //   [1] C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow".
164 //   [2] Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation".
165 CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_DualTVL1();
166
167 } // cv
168
169 #endif