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 //! @addtogroup video_track 54 //! @{ 55 56 enum { OPTFLOW_USE_INITIAL_FLOW = 4, 57 OPTFLOW_LK_GET_MIN_EIGENVALS = 8, 58 OPTFLOW_FARNEBACK_GAUSSIAN = 256 59 }; 60 61 /** @brief Finds an object center, size, and orientation. 62 63 @param probImage Back projection of the object histogram. See calcBackProject. 64 @param window Initial search window. 65 @param criteria Stop criteria for the underlying meanShift. 66 returns 67 (in old interfaces) Number of iterations CAMSHIFT took to converge 68 The function implements the CAMSHIFT object tracking algorithm @cite Bradski98 . First, it finds an 69 object center using meanShift and then adjusts the window size and finds the optimal rotation. The 70 function returns the rotated rectangle structure that includes the object position, size, and 71 orientation. The next position of the search window can be obtained with RotatedRect::boundingRect() 72 73 See the OpenCV sample camshiftdemo.c that tracks colored objects. 74 75 @note 76 - (Python) A sample explaining the camshift tracking algorithm can be found at 77 opencv_source_code/samples/python/camshift.py 78 */ 79 CV_EXPORTS_W RotatedRect CamShift( InputArray probImage, CV_IN_OUT Rect& window, 80 TermCriteria criteria ); 81 /** @example samples/cpp/camshiftdemo.cpp 82 An example using the mean-shift tracking algorithm 83 */ 84 85 /** @brief Finds an object on a back projection image. 86 87 @param probImage Back projection of the object histogram. See calcBackProject for details. 88 @param window Initial search window. 89 @param criteria Stop criteria for the iterative search algorithm. 90 returns 91 : Number of iterations CAMSHIFT took to converge. 92 The function implements the iterative object search algorithm. It takes the input back projection of 93 an object and the initial position. The mass center in window of the back projection image is 94 computed and the search window center shifts to the mass center. The procedure is repeated until the 95 specified number of iterations criteria.maxCount is done or until the window center shifts by less 96 than criteria.epsilon. The algorithm is used inside CamShift and, unlike CamShift , the search 97 window size or orientation do not change during the search. You can simply pass the output of 98 calcBackProject to this function. But better results can be obtained if you pre-filter the back 99 projection and remove the noise. For example, you can do this by retrieving connected components 100 with findContours , throwing away contours with small area ( contourArea ), and rendering the 101 remaining contours with drawContours. 102 103 */ 104 CV_EXPORTS_W int meanShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria ); 105 106 /** @brief Constructs the image pyramid which can be passed to calcOpticalFlowPyrLK. 107 108 @param img 8-bit input image. 109 @param pyramid output pyramid. 110 @param winSize window size of optical flow algorithm. Must be not less than winSize argument of 111 calcOpticalFlowPyrLK. It is needed to calculate required padding for pyramid levels. 112 @param maxLevel 0-based maximal pyramid level number. 113 @param withDerivatives set to precompute gradients for the every pyramid level. If pyramid is 114 constructed without the gradients then calcOpticalFlowPyrLK will calculate them internally. 115 @param pyrBorder the border mode for pyramid layers. 116 @param derivBorder the border mode for gradients. 117 @param tryReuseInputImage put ROI of input image into the pyramid if possible. You can pass false 118 to force data copying. 119 @return number of levels in constructed pyramid. Can be less than maxLevel. 120 */ 121 CV_EXPORTS_W int buildOpticalFlowPyramid( InputArray img, OutputArrayOfArrays pyramid, 122 Size winSize, int maxLevel, bool withDerivatives = true, 123 int pyrBorder = BORDER_REFLECT_101, 124 int derivBorder = BORDER_CONSTANT, 125 bool tryReuseInputImage = true ); 126 127 /** @example samples/cpp/lkdemo.cpp 128 An example using the Lucas-Kanade optical flow algorithm 129 */ 130 131 /** @brief Calculates an optical flow for a sparse feature set using the iterative Lucas-Kanade method with 132 pyramids. 133 134 @param prevImg first 8-bit input image or pyramid constructed by buildOpticalFlowPyramid. 135 @param nextImg second input image or pyramid of the same size and the same type as prevImg. 136 @param prevPts vector of 2D points for which the flow needs to be found; point coordinates must be 137 single-precision floating-point numbers. 138 @param nextPts output vector of 2D points (with single-precision floating-point coordinates) 139 containing the calculated new positions of input features in the second image; when 140 OPTFLOW_USE_INITIAL_FLOW flag is passed, the vector must have the same size as in the input. 141 @param status output status vector (of unsigned chars); each element of the vector is set to 1 if 142 the flow for the corresponding features has been found, otherwise, it is set to 0. 143 @param err output vector of errors; each element of the vector is set to an error for the 144 corresponding feature, type of the error measure can be set in flags parameter; if the flow wasn't 145 found then the error is not defined (use the status parameter to find such cases). 146 @param winSize size of the search window at each pyramid level. 147 @param maxLevel 0-based maximal pyramid level number; if set to 0, pyramids are not used (single 148 level), if set to 1, two levels are used, and so on; if pyramids are passed to input then 149 algorithm will use as many levels as pyramids have but no more than maxLevel. 150 @param criteria parameter, specifying the termination criteria of the iterative search algorithm 151 (after the specified maximum number of iterations criteria.maxCount or when the search window 152 moves by less than criteria.epsilon. 153 @param flags operation flags: 154 - **OPTFLOW_USE_INITIAL_FLOW** uses initial estimations, stored in nextPts; if the flag is 155 not set, then prevPts is copied to nextPts and is considered the initial estimate. 156 - **OPTFLOW_LK_GET_MIN_EIGENVALS** use minimum eigen values as an error measure (see 157 minEigThreshold description); if the flag is not set, then L1 distance between patches 158 around the original and a moved point, divided by number of pixels in a window, is used as a 159 error measure. 160 @param minEigThreshold the algorithm calculates the minimum eigen value of a 2x2 normal matrix of 161 optical flow equations (this matrix is called a spatial gradient matrix in @cite Bouguet00), divided 162 by number of pixels in a window; if this value is less than minEigThreshold, then a corresponding 163 feature is filtered out and its flow is not processed, so it allows to remove bad points and get a 164 performance boost. 165 166 The function implements a sparse iterative version of the Lucas-Kanade optical flow in pyramids. See 167 @cite Bouguet00 . The function is parallelized with the TBB library. 168 169 @note 170 171 - An example using the Lucas-Kanade optical flow algorithm can be found at 172 opencv_source_code/samples/cpp/lkdemo.cpp 173 - (Python) An example using the Lucas-Kanade optical flow algorithm can be found at 174 opencv_source_code/samples/python/lk_track.py 175 - (Python) An example using the Lucas-Kanade tracker for homography matching can be found at 176 opencv_source_code/samples/python/lk_homography.py 177 */ 178 CV_EXPORTS_W void calcOpticalFlowPyrLK( InputArray prevImg, InputArray nextImg, 179 InputArray prevPts, InputOutputArray nextPts, 180 OutputArray status, OutputArray err, 181 Size winSize = Size(21,21), int maxLevel = 3, 182 TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), 183 int flags = 0, double minEigThreshold = 1e-4 ); 184 185 /** @brief Computes a dense optical flow using the Gunnar Farneback's algorithm. 186 187 @param prev first 8-bit single-channel input image. 188 @param next second input image of the same size and the same type as prev. 189 @param flow computed flow image that has the same size as prev and type CV_32FC2. 190 @param pyr_scale parameter, specifying the image scale (\<1) to build pyramids for each image; 191 pyr_scale=0.5 means a classical pyramid, where each next layer is twice smaller than the previous 192 one. 193 @param levels number of pyramid layers including the initial image; levels=1 means that no extra 194 layers are created and only the original images are used. 195 @param winsize averaging window size; larger values increase the algorithm robustness to image 196 noise and give more chances for fast motion detection, but yield more blurred motion field. 197 @param iterations number of iterations the algorithm does at each pyramid level. 198 @param poly_n size of the pixel neighborhood used to find polynomial expansion in each pixel; 199 larger values mean that the image will be approximated with smoother surfaces, yielding more 200 robust algorithm and more blurred motion field, typically poly_n =5 or 7. 201 @param poly_sigma standard deviation of the Gaussian that is used to smooth derivatives used as a 202 basis for the polynomial expansion; for poly_n=5, you can set poly_sigma=1.1, for poly_n=7, a 203 good value would be poly_sigma=1.5. 204 @param flags operation flags that can be a combination of the following: 205 - **OPTFLOW_USE_INITIAL_FLOW** uses the input flow as an initial flow approximation. 206 - **OPTFLOW_FARNEBACK_GAUSSIAN** uses the Gaussian \f$\texttt{winsize}\times\texttt{winsize}\f$ 207 filter instead of a box filter of the same size for optical flow estimation; usually, this 208 option gives z more accurate flow than with a box filter, at the cost of lower speed; 209 normally, winsize for a Gaussian window should be set to a larger value to achieve the same 210 level of robustness. 211 212 The function finds an optical flow for each prev pixel using the @cite Farneback2003 algorithm so that 213 214 \f[\texttt{prev} (y,x) \sim \texttt{next} ( y + \texttt{flow} (y,x)[1], x + \texttt{flow} (y,x)[0])\f] 215 216 @note 217 218 - An example using the optical flow algorithm described by Gunnar Farneback can be found at 219 opencv_source_code/samples/cpp/fback.cpp 220 - (Python) An example using the optical flow algorithm described by Gunnar Farneback can be 221 found at opencv_source_code/samples/python/opt_flow.py 222 */ 223 CV_EXPORTS_W void calcOpticalFlowFarneback( InputArray prev, InputArray next, InputOutputArray flow, 224 double pyr_scale, int levels, int winsize, 225 int iterations, int poly_n, double poly_sigma, 226 int flags ); 227 228 /** @brief Computes an optimal affine transformation between two 2D point sets. 229 230 @param src First input 2D point set stored in std::vector or Mat, or an image stored in Mat. 231 @param dst Second input 2D point set of the same size and the same type as A, or another image. 232 @param fullAffine If true, the function finds an optimal affine transformation with no additional 233 restrictions (6 degrees of freedom). Otherwise, the class of transformations to choose from is 234 limited to combinations of translation, rotation, and uniform scaling (4 degrees of freedom). 235 236 The function finds an optimal affine transform *[A|b]* (a 2 x 3 floating-point matrix) that 237 approximates best the affine transformation between: 238 239 * Two point sets 240 * Two raster images. In this case, the function first finds some features in the src image and 241 finds the corresponding features in dst image. After that, the problem is reduced to the first 242 case. 243 In case of point sets, the problem is formulated as follows: you need to find a 2x2 matrix *A* and 244 2x1 vector *b* so that: 245 246 \f[[A^*|b^*] = arg \min _{[A|b]} \sum _i \| \texttt{dst}[i] - A { \texttt{src}[i]}^T - b \| ^2\f] 247 where src[i] and dst[i] are the i-th points in src and dst, respectively 248 \f$[A|b]\f$ can be either arbitrary (when fullAffine=true ) or have a form of 249 \f[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ -a_{12} & a_{11} & b_2 \end{bmatrix}\f] 250 when fullAffine=false. 251 252 @sa 253 estimateAffine2D, estimateAffinePartial2D, getAffineTransform, getPerspectiveTransform, findHomography 254 */ 255 CV_EXPORTS_W Mat estimateRigidTransform( InputArray src, InputArray dst, bool fullAffine); 256 CV_EXPORTS_W Mat estimateRigidTransform( InputArray src, InputArray dst, bool fullAffine, int ransacMaxIters, double ransacGoodRatio, 257 int ransacSize0); 258 259 260 enum 261 { 262 MOTION_TRANSLATION = 0, 263 MOTION_EUCLIDEAN = 1, 264 MOTION_AFFINE = 2, 265 MOTION_HOMOGRAPHY = 3 266 }; 267 268 /** @example samples/cpp/image_alignment.cpp 269 An example using the image alignment ECC algorithm 270 */ 271 272 /** @brief Finds the geometric transform (warp) between two images in terms of the ECC criterion @cite EP08 . 273 274 @param templateImage single-channel template image; CV_8U or CV_32F array. 275 @param inputImage single-channel input image which should be warped with the final warpMatrix in 276 order to provide an image similar to templateImage, same type as temlateImage. 277 @param warpMatrix floating-point \f$2\times 3\f$ or \f$3\times 3\f$ mapping matrix (warp). 278 @param motionType parameter, specifying the type of motion: 279 - **MOTION_TRANSLATION** sets a translational motion model; warpMatrix is \f$2\times 3\f$ with 280 the first \f$2\times 2\f$ part being the unity matrix and the rest two parameters being 281 estimated. 282 - **MOTION_EUCLIDEAN** sets a Euclidean (rigid) transformation as motion model; three 283 parameters are estimated; warpMatrix is \f$2\times 3\f$. 284 - **MOTION_AFFINE** sets an affine motion model (DEFAULT); six parameters are estimated; 285 warpMatrix is \f$2\times 3\f$. 286 - **MOTION_HOMOGRAPHY** sets a homography as a motion model; eight parameters are 287 estimated;\`warpMatrix\` is \f$3\times 3\f$. 288 @param criteria parameter, specifying the termination criteria of the ECC algorithm; 289 criteria.epsilon defines the threshold of the increment in the correlation coefficient between two 290 iterations (a negative criteria.epsilon makes criteria.maxcount the only termination criterion). 291 Default values are shown in the declaration above. 292 @param inputMask An optional mask to indicate valid values of inputImage. 293 294 The function estimates the optimum transformation (warpMatrix) with respect to ECC criterion 295 (@cite EP08), that is 296 297 \f[\texttt{warpMatrix} = \texttt{warpMatrix} = \arg\max_{W} \texttt{ECC}(\texttt{templateImage}(x,y),\texttt{inputImage}(x',y'))\f] 298 299 where 300 301 \f[\begin{bmatrix} x' \\ y' \end{bmatrix} = W \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}\f] 302 303 (the equation holds with homogeneous coordinates for homography). It returns the final enhanced 304 correlation coefficient, that is the correlation coefficient between the template image and the 305 final warped input image. When a \f$3\times 3\f$ matrix is given with motionType =0, 1 or 2, the third 306 row is ignored. 307 308 Unlike findHomography and estimateRigidTransform, the function findTransformECC implements an 309 area-based alignment that builds on intensity similarities. In essence, the function updates the 310 initial transformation that roughly aligns the images. If this information is missing, the identity 311 warp (unity matrix) is used as an initialization. Note that if images undergo strong 312 displacements/rotations, an initial transformation that roughly aligns the images is necessary 313 (e.g., a simple euclidean/similarity transform that allows for the images showing the same image 314 content approximately). Use inverse warping in the second image to take an image close to the first 315 one, i.e. use the flag WARP_INVERSE_MAP with warpAffine or warpPerspective. See also the OpenCV 316 sample image_alignment.cpp that demonstrates the use of the function. Note that the function throws 317 an exception if algorithm does not converges. 318 319 @sa 320 estimateAffine2D, estimateAffinePartial2D, findHomography 321 */ 322 CV_EXPORTS_W double findTransformECC( InputArray templateImage, InputArray inputImage, 323 InputOutputArray warpMatrix, int motionType = MOTION_AFFINE, 324 TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001), 325 InputArray inputMask = noArray()); 326 327 /** @example samples/cpp/kalman.cpp 328 An example using the standard Kalman filter 329 */ 330 331 /** @brief Kalman filter class. 332 333 The class implements a standard Kalman filter <http://en.wikipedia.org/wiki/Kalman_filter>, 334 @cite Welch95 . However, you can modify transitionMatrix, controlMatrix, and measurementMatrix to get 335 an extended Kalman filter functionality. 336 @note In C API when CvKalman\* kalmanFilter structure is not needed anymore, it should be released 337 with cvReleaseKalman(&kalmanFilter) 338 */ 339 class CV_EXPORTS_W KalmanFilter 340 { 341 public: 342 CV_WRAP KalmanFilter(); 343 /** @overload 344 @param dynamParams Dimensionality of the state. 345 @param measureParams Dimensionality of the measurement. 346 @param controlParams Dimensionality of the control vector. 347 @param type Type of the created matrices that should be CV_32F or CV_64F. 348 */ 349 CV_WRAP KalmanFilter( int dynamParams, int measureParams, int controlParams = 0, int type = CV_32F ); 350 351 /** @brief Re-initializes Kalman filter. The previous content is destroyed. 352 353 @param dynamParams Dimensionality of the state. 354 @param measureParams Dimensionality of the measurement. 355 @param controlParams Dimensionality of the control vector. 356 @param type Type of the created matrices that should be CV_32F or CV_64F. 357 */ 358 void init( int dynamParams, int measureParams, int controlParams = 0, int type = CV_32F ); 359 360 /** @brief Computes a predicted state. 361 362 @param control The optional input control 363 */ 364 CV_WRAP const Mat& predict( const Mat& control = Mat() ); 365 366 /** @brief Updates the predicted state from the measurement. 367 368 @param measurement The measured system parameters 369 */ 370 CV_WRAP const Mat& correct( const Mat& measurement ); 371 372 CV_PROP_RW Mat statePre; //!< predicted state (x'(k)): x(k)=A*x(k-1)+B*u(k) 373 CV_PROP_RW Mat statePost; //!< corrected state (x(k)): x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) 374 CV_PROP_RW Mat transitionMatrix; //!< state transition matrix (A) 375 CV_PROP_RW Mat controlMatrix; //!< control matrix (B) (not used if there is no control) 376 CV_PROP_RW Mat measurementMatrix; //!< measurement matrix (H) 377 CV_PROP_RW Mat processNoiseCov; //!< process noise covariance matrix (Q) 378 CV_PROP_RW Mat measurementNoiseCov;//!< measurement noise covariance matrix (R) 379 CV_PROP_RW Mat errorCovPre; //!< priori error estimate covariance matrix (P'(k)): P'(k)=A*P(k-1)*At + Q)*/ 380 CV_PROP_RW Mat gain; //!< Kalman gain matrix (K(k)): K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R) 381 CV_PROP_RW Mat errorCovPost; //!< posteriori error estimate covariance matrix (P(k)): P(k)=(I-K(k)*H)*P'(k) 382 383 // temporary matrices 384 Mat temp1; 385 Mat temp2; 386 Mat temp3; 387 Mat temp4; 388 Mat temp5; 389 }; 390 391 392 class CV_EXPORTS_W DenseOpticalFlow : public Algorithm 393 { 394 public: 395 /** @brief Calculates an optical flow. 396 397 @param I0 first 8-bit single-channel input image. 398 @param I1 second input image of the same size and the same type as prev. 399 @param flow computed flow image that has the same size as prev and type CV_32FC2. 400 */ 401 CV_WRAP virtual void calc( InputArray I0, InputArray I1, InputOutputArray flow ) = 0; 402 /** @brief Releases all inner buffers. 403 */ 404 CV_WRAP virtual void collectGarbage() = 0; 405 }; 406 407 /** @brief Base interface for sparse optical flow algorithms. 408 */ 409 class CV_EXPORTS_W SparseOpticalFlow : public Algorithm 410 { 411 public: 412 /** @brief Calculates a sparse optical flow. 413 414 @param prevImg First input image. 415 @param nextImg Second input image of the same size and the same type as prevImg. 416 @param prevPts Vector of 2D points for which the flow needs to be found. 417 @param nextPts Output vector of 2D points containing the calculated new positions of input features in the second image. 418 @param status Output status vector. Each element of the vector is set to 1 if the 419 flow for the corresponding features has been found. Otherwise, it is set to 0. 420 @param err Optional output vector that contains error response for each point (inverse confidence). 421 */ 422 CV_WRAP virtual void calc(InputArray prevImg, InputArray nextImg, 423 InputArray prevPts, InputOutputArray nextPts, 424 OutputArray status, 425 OutputArray err = cv::noArray()) = 0; 426 }; 427 428 /** @brief "Dual TV L1" Optical Flow Algorithm. 429 430 The class implements the "Dual TV L1" optical flow algorithm described in @cite Zach2007 and 431 @cite Javier2012 . 432 Here are important members of the class that control the algorithm, which you can set after 433 constructing the class instance: 434 435 - member double tau 436 Time step of the numerical scheme. 437 438 - member double lambda 439 Weight parameter for the data term, attachment parameter. This is the most relevant 440 parameter, which determines the smoothness of the output. The smaller this parameter is, 441 the smoother the solutions we obtain. It depends on the range of motions of the images, so 442 its value should be adapted to each image sequence. 443 444 - member double theta 445 Weight parameter for (u - v)\^2, tightness parameter. It serves as a link between the 446 attachment and the regularization terms. In theory, it should have a small value in order 447 to maintain both parts in correspondence. The method is stable for a large range of values 448 of this parameter. 449 450 - member int nscales 451 Number of scales used to create the pyramid of images. 452 453 - member int warps 454 Number of warpings per scale. Represents the number of times that I1(x+u0) and grad( 455 I1(x+u0) ) are computed per scale. This is a parameter that assures the stability of the 456 method. It also affects the running time, so it is a compromise between speed and 457 accuracy. 458 459 - member double epsilon 460 Stopping criterion threshold used in the numerical scheme, which is a trade-off between 461 precision and running time. A small value will yield more accurate solutions at the 462 expense of a slower convergence. 463 464 - member int iterations 465 Stopping criterion iterations number used in the numerical scheme. 466 467 C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow". 468 Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation". 469 */ 470 class CV_EXPORTS_W DualTVL1OpticalFlow : public DenseOpticalFlow 471 { 472 public: 473 //! @brief Time step of the numerical scheme 474 /** @see setTau */ 475 CV_WRAP virtual double getTau() const = 0; 476 /** @copybrief getTau @see getTau */ 477 CV_WRAP virtual void setTau(double val) = 0; 478 //! @brief Weight parameter for the data term, attachment parameter 479 /** @see setLambda */ 480 CV_WRAP virtual double getLambda() const = 0; 481 /** @copybrief getLambda @see getLambda */ 482 CV_WRAP virtual void setLambda(double val) = 0; 483 //! @brief Weight parameter for (u - v)^2, tightness parameter 484 /** @see setTheta */ 485 CV_WRAP virtual double getTheta() const = 0; 486 /** @copybrief getTheta @see getTheta */ 487 CV_WRAP virtual void setTheta(double val) = 0; 488 //! @brief coefficient for additional illumination variation term 489 /** @see setGamma */ 490 CV_WRAP virtual double getGamma() const = 0; 491 /** @copybrief getGamma @see getGamma */ 492 CV_WRAP virtual void setGamma(double val) = 0; 493 //! @brief Number of scales used to create the pyramid of images 494 /** @see setScalesNumber */ 495 CV_WRAP virtual int getScalesNumber() const = 0; 496 /** @copybrief getScalesNumber @see getScalesNumber */ 497 CV_WRAP virtual void setScalesNumber(int val) = 0; 498 //! @brief Number of warpings per scale 499 /** @see setWarpingsNumber */ 500 CV_WRAP virtual int getWarpingsNumber() const = 0; 501 /** @copybrief getWarpingsNumber @see getWarpingsNumber */ 502 CV_WRAP virtual void setWarpingsNumber(int val) = 0; 503 //! @brief Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time 504 /** @see setEpsilon */ 505 CV_WRAP virtual double getEpsilon() const = 0; 506 /** @copybrief getEpsilon @see getEpsilon */ 507 CV_WRAP virtual void setEpsilon(double val) = 0; 508 //! @brief Inner iterations (between outlier filtering) used in the numerical scheme 509 /** @see setInnerIterations */ 510 CV_WRAP virtual int getInnerIterations() const = 0; 511 /** @copybrief getInnerIterations @see getInnerIterations */ 512 CV_WRAP virtual void setInnerIterations(int val) = 0; 513 //! @brief Outer iterations (number of inner loops) used in the numerical scheme 514 /** @see setOuterIterations */ 515 CV_WRAP virtual int getOuterIterations() const = 0; 516 /** @copybrief getOuterIterations @see getOuterIterations */ 517 CV_WRAP virtual void setOuterIterations(int val) = 0; 518 //! @brief Use initial flow 519 /** @see setUseInitialFlow */ 520 CV_WRAP virtual bool getUseInitialFlow() const = 0; 521 /** @copybrief getUseInitialFlow @see getUseInitialFlow */ 522 CV_WRAP virtual void setUseInitialFlow(bool val) = 0; 523 //! @brief Step between scales (<1) 524 /** @see setScaleStep */ 525 CV_WRAP virtual double getScaleStep() const = 0; 526 /** @copybrief getScaleStep @see getScaleStep */ 527 CV_WRAP virtual void setScaleStep(double val) = 0; 528 //! @brief Median filter kernel size (1 = no filter) (3 or 5) 529 /** @see setMedianFiltering */ 530 CV_WRAP virtual int getMedianFiltering() const = 0; 531 /** @copybrief getMedianFiltering @see getMedianFiltering */ 532 CV_WRAP virtual void setMedianFiltering(int val) = 0; 533 534 /** @brief Creates instance of cv::DualTVL1OpticalFlow*/ 535 CV_WRAP static Ptr<DualTVL1OpticalFlow> create( 536 double tau = 0.25, 537 double lambda = 0.15, 538 double theta = 0.3, 539 int nscales = 5, 540 int warps = 5, 541 double epsilon = 0.01, 542 int innnerIterations = 30, 543 int outerIterations = 10, 544 double scaleStep = 0.8, 545 double gamma = 0.0, 546 int medianFiltering = 5, 547 bool useInitialFlow = false); 548 }; 549 550 /** @brief Creates instance of cv::DenseOpticalFlow 551 */ 552 CV_EXPORTS_W Ptr<DualTVL1OpticalFlow> createOptFlow_DualTVL1(); 553 554 /** @brief Class computing a dense optical flow using the Gunnar Farneback's algorithm. 555 */ 556 class CV_EXPORTS_W FarnebackOpticalFlow : public DenseOpticalFlow 557 { 558 public: 559 CV_WRAP virtual int getNumLevels() const = 0; 560 CV_WRAP virtual void setNumLevels(int numLevels) = 0; 561 562 CV_WRAP virtual double getPyrScale() const = 0; 563 CV_WRAP virtual void setPyrScale(double pyrScale) = 0; 564 565 CV_WRAP virtual bool getFastPyramids() const = 0; 566 CV_WRAP virtual void setFastPyramids(bool fastPyramids) = 0; 567 568 CV_WRAP virtual int getWinSize() const = 0; 569 CV_WRAP virtual void setWinSize(int winSize) = 0; 570 571 CV_WRAP virtual int getNumIters() const = 0; 572 CV_WRAP virtual void setNumIters(int numIters) = 0; 573 574 CV_WRAP virtual int getPolyN() const = 0; 575 CV_WRAP virtual void setPolyN(int polyN) = 0; 576 577 CV_WRAP virtual double getPolySigma() const = 0; 578 CV_WRAP virtual void setPolySigma(double polySigma) = 0; 579 580 CV_WRAP virtual int getFlags() const = 0; 581 CV_WRAP virtual void setFlags(int flags) = 0; 582 583 CV_WRAP static Ptr<FarnebackOpticalFlow> create( 584 int numLevels = 5, 585 double pyrScale = 0.5, 586 bool fastPyramids = false, 587 int winSize = 13, 588 int numIters = 10, 589 int polyN = 5, 590 double polySigma = 1.1, 591 int flags = 0); 592 }; 593 594 595 /** @brief Class used for calculating a sparse optical flow. 596 597 The class can calculate an optical flow for a sparse feature set using the 598 iterative Lucas-Kanade method with pyramids. 599 600 @sa calcOpticalFlowPyrLK 601 602 */ 603 class CV_EXPORTS_W SparsePyrLKOpticalFlow : public SparseOpticalFlow 604 { 605 public: 606 CV_WRAP virtual Size getWinSize() const = 0; 607 CV_WRAP virtual void setWinSize(Size winSize) = 0; 608 609 CV_WRAP virtual int getMaxLevel() const = 0; 610 CV_WRAP virtual void setMaxLevel(int maxLevel) = 0; 611 612 CV_WRAP virtual TermCriteria getTermCriteria() const = 0; 613 CV_WRAP virtual void setTermCriteria(TermCriteria& crit) = 0; 614 615 CV_WRAP virtual int getFlags() const = 0; 616 CV_WRAP virtual void setFlags(int flags) = 0; 617 618 CV_WRAP virtual double getMinEigThreshold() const = 0; 619 CV_WRAP virtual void setMinEigThreshold(double minEigThreshold) = 0; 620 621 CV_WRAP static Ptr<SparsePyrLKOpticalFlow> create( 622 Size winSize = Size(21, 21), 623 int maxLevel = 3, TermCriteria crit = 624 TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), 625 int flags = 0, 626 double minEigThreshold = 1e-4); 627 }; 628 629 //! @} video_track 630 631 } // cv 632 633 #endif 634