/work/install-coverage/include/opencv4/opencv2/video/tracking.hpp
Line | Count | Source |
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 | | #ifdef HAVE_OPENCV_DNN |
50 | | # include "opencv2/dnn.hpp" |
51 | | #endif |
52 | | |
53 | | namespace cv |
54 | | { |
55 | | |
56 | | //! @addtogroup video_track |
57 | | //! @{ |
58 | | |
59 | | enum { OPTFLOW_USE_INITIAL_FLOW = 4, |
60 | | OPTFLOW_LK_GET_MIN_EIGENVALS = 8, |
61 | | OPTFLOW_FARNEBACK_GAUSSIAN = 256 |
62 | | }; |
63 | | |
64 | | /** @brief Finds an object center, size, and orientation. |
65 | | |
66 | | @param probImage Back projection of the object histogram. See calcBackProject. |
67 | | @param window Initial search window. |
68 | | @param criteria Stop criteria for the underlying meanShift. |
69 | | returns |
70 | | (in old interfaces) Number of iterations CAMSHIFT took to converge |
71 | | The function implements the CAMSHIFT object tracking algorithm @cite Bradski98 . First, it finds an |
72 | | object center using meanShift and then adjusts the window size and finds the optimal rotation. The |
73 | | function returns the rotated rectangle structure that includes the object position, size, and |
74 | | orientation. The next position of the search window can be obtained with RotatedRect::boundingRect() |
75 | | |
76 | | See the OpenCV sample camshiftdemo.c that tracks colored objects. |
77 | | |
78 | | @note |
79 | | - (Python) A sample explaining the camshift tracking algorithm can be found at |
80 | | opencv_source_code/samples/python/camshift.py |
81 | | */ |
82 | | CV_EXPORTS_W RotatedRect CamShift( InputArray probImage, CV_IN_OUT Rect& window, |
83 | | TermCriteria criteria ); |
84 | | /** @example samples/cpp/camshiftdemo.cpp |
85 | | An example using the mean-shift tracking algorithm |
86 | | */ |
87 | | |
88 | | /** @brief Finds an object on a back projection image. |
89 | | |
90 | | @param probImage Back projection of the object histogram. See calcBackProject for details. |
91 | | @param window Initial search window. |
92 | | @param criteria Stop criteria for the iterative search algorithm. |
93 | | returns |
94 | | : Number of iterations CAMSHIFT took to converge. |
95 | | The function implements the iterative object search algorithm. It takes the input back projection of |
96 | | an object and the initial position. The mass center in window of the back projection image is |
97 | | computed and the search window center shifts to the mass center. The procedure is repeated until the |
98 | | specified number of iterations criteria.maxCount is done or until the window center shifts by less |
99 | | than criteria.epsilon. The algorithm is used inside CamShift and, unlike CamShift , the search |
100 | | window size or orientation do not change during the search. You can simply pass the output of |
101 | | calcBackProject to this function. But better results can be obtained if you pre-filter the back |
102 | | projection and remove the noise. For example, you can do this by retrieving connected components |
103 | | with findContours , throwing away contours with small area ( contourArea ), and rendering the |
104 | | remaining contours with drawContours. |
105 | | |
106 | | */ |
107 | | CV_EXPORTS_W int meanShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria ); |
108 | | |
109 | | /** @brief Constructs the image pyramid which can be passed to calcOpticalFlowPyrLK. |
110 | | |
111 | | @param img 8-bit input image. |
112 | | @param pyramid output pyramid. |
113 | | @param winSize window size of optical flow algorithm. Must be not less than winSize argument of |
114 | | calcOpticalFlowPyrLK. It is needed to calculate required padding for pyramid levels. |
115 | | @param maxLevel 0-based maximal pyramid level number. |
116 | | @param withDerivatives set to precompute gradients for the every pyramid level. If pyramid is |
117 | | constructed without the gradients then calcOpticalFlowPyrLK will calculate them internally. |
118 | | @param pyrBorder the border mode for pyramid layers. |
119 | | @param derivBorder the border mode for gradients. |
120 | | @param tryReuseInputImage put ROI of input image into the pyramid if possible. You can pass false |
121 | | to force data copying. |
122 | | @return number of levels in constructed pyramid. Can be less than maxLevel. |
123 | | */ |
124 | | CV_EXPORTS_W int buildOpticalFlowPyramid( InputArray img, OutputArrayOfArrays pyramid, |
125 | | Size winSize, int maxLevel, bool withDerivatives = true, |
126 | | int pyrBorder = BORDER_REFLECT_101, |
127 | | int derivBorder = BORDER_CONSTANT, |
128 | | bool tryReuseInputImage = true ); |
129 | | |
130 | | /** @example samples/cpp/lkdemo.cpp |
131 | | An example using the Lucas-Kanade optical flow algorithm |
132 | | */ |
133 | | |
134 | | /** @brief Calculates an optical flow for a sparse feature set using the iterative Lucas-Kanade method with |
135 | | pyramids. |
136 | | |
137 | | @param prevImg first 8-bit input image or pyramid constructed by buildOpticalFlowPyramid. |
138 | | @param nextImg second input image or pyramid of the same size and the same type as prevImg. |
139 | | @param prevPts vector of 2D points for which the flow needs to be found; point coordinates must be |
140 | | single-precision floating-point numbers. |
141 | | @param nextPts output vector of 2D points (with single-precision floating-point coordinates) |
142 | | containing the calculated new positions of input features in the second image; when |
143 | | OPTFLOW_USE_INITIAL_FLOW flag is passed, the vector must have the same size as in the input. |
144 | | @param status output status vector (of unsigned chars); each element of the vector is set to 1 if |
145 | | the flow for the corresponding features has been found, otherwise, it is set to 0. |
146 | | @param err output vector of errors; each element of the vector is set to an error for the |
147 | | corresponding feature, type of the error measure can be set in flags parameter; if the flow wasn't |
148 | | found then the error is not defined (use the status parameter to find such cases). |
149 | | @param winSize size of the search window at each pyramid level. |
150 | | @param maxLevel 0-based maximal pyramid level number; if set to 0, pyramids are not used (single |
151 | | level), if set to 1, two levels are used, and so on; if pyramids are passed to input then |
152 | | algorithm will use as many levels as pyramids have but no more than maxLevel. |
153 | | @param criteria parameter, specifying the termination criteria of the iterative search algorithm |
154 | | (after the specified maximum number of iterations criteria.maxCount or when the search window |
155 | | moves by less than criteria.epsilon. |
156 | | @param flags operation flags: |
157 | | - **OPTFLOW_USE_INITIAL_FLOW** uses initial estimations, stored in nextPts; if the flag is |
158 | | not set, then prevPts is copied to nextPts and is considered the initial estimate. |
159 | | - **OPTFLOW_LK_GET_MIN_EIGENVALS** use minimum eigen values as an error measure (see |
160 | | minEigThreshold description); if the flag is not set, then L1 distance between patches |
161 | | around the original and a moved point, divided by number of pixels in a window, is used as a |
162 | | error measure. |
163 | | @param minEigThreshold the algorithm calculates the minimum eigen value of a 2x2 normal matrix of |
164 | | optical flow equations (this matrix is called a spatial gradient matrix in @cite Bouguet00), divided |
165 | | by number of pixels in a window; if this value is less than minEigThreshold, then a corresponding |
166 | | feature is filtered out and its flow is not processed, so it allows to remove bad points and get a |
167 | | performance boost. |
168 | | |
169 | | The function implements a sparse iterative version of the Lucas-Kanade optical flow in pyramids. See |
170 | | @cite Bouguet00 . The function is parallelized with the TBB library. |
171 | | |
172 | | @note Some examples: |
173 | | |
174 | | - An example using the Lucas-Kanade optical flow algorithm can be found at |
175 | | opencv_source_code/samples/cpp/lkdemo.cpp |
176 | | - (Python) An example using the Lucas-Kanade optical flow algorithm can be found at |
177 | | opencv_source_code/samples/python/lk_track.py |
178 | | - (Python) An example using the Lucas-Kanade tracker for homography matching can be found at |
179 | | opencv_source_code/samples/python/lk_homography.py |
180 | | */ |
181 | | CV_EXPORTS_W void calcOpticalFlowPyrLK( InputArray prevImg, InputArray nextImg, |
182 | | InputArray prevPts, InputOutputArray nextPts, |
183 | | OutputArray status, OutputArray err, |
184 | | Size winSize = Size(21,21), int maxLevel = 3, |
185 | | TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), |
186 | | int flags = 0, double minEigThreshold = 1e-4 ); |
187 | | |
188 | | /** @brief Computes a dense optical flow using the Gunnar Farneback's algorithm. |
189 | | |
190 | | @param prev first 8-bit single-channel input image. |
191 | | @param next second input image of the same size and the same type as prev. |
192 | | @param flow computed flow image that has the same size as prev and type CV_32FC2. |
193 | | @param pyr_scale parameter, specifying the image scale (\<1) to build pyramids for each image; |
194 | | pyr_scale=0.5 means a classical pyramid, where each next layer is twice smaller than the previous |
195 | | one. |
196 | | @param levels number of pyramid layers including the initial image; levels=1 means that no extra |
197 | | layers are created and only the original images are used. |
198 | | @param winsize averaging window size; larger values increase the algorithm robustness to image |
199 | | noise and give more chances for fast motion detection, but yield more blurred motion field. |
200 | | @param iterations number of iterations the algorithm does at each pyramid level. |
201 | | @param poly_n size of the pixel neighborhood used to find polynomial expansion in each pixel; |
202 | | larger values mean that the image will be approximated with smoother surfaces, yielding more |
203 | | robust algorithm and more blurred motion field, typically poly_n =5 or 7. |
204 | | @param poly_sigma standard deviation of the Gaussian that is used to smooth derivatives used as a |
205 | | basis for the polynomial expansion; for poly_n=5, you can set poly_sigma=1.1, for poly_n=7, a |
206 | | good value would be poly_sigma=1.5. |
207 | | @param flags operation flags that can be a combination of the following: |
208 | | - **OPTFLOW_USE_INITIAL_FLOW** uses the input flow as an initial flow approximation. |
209 | | - **OPTFLOW_FARNEBACK_GAUSSIAN** uses the Gaussian \f$\texttt{winsize}\times\texttt{winsize}\f$ |
210 | | filter instead of a box filter of the same size for optical flow estimation; usually, this |
211 | | option gives z more accurate flow than with a box filter, at the cost of lower speed; |
212 | | normally, winsize for a Gaussian window should be set to a larger value to achieve the same |
213 | | level of robustness. |
214 | | |
215 | | The function finds an optical flow for each prev pixel using the @cite Farneback2003 algorithm so that |
216 | | |
217 | | \f[\texttt{prev} (y,x) \sim \texttt{next} ( y + \texttt{flow} (y,x)[1], x + \texttt{flow} (y,x)[0])\f] |
218 | | |
219 | | @note Some examples: |
220 | | |
221 | | - An example using the optical flow algorithm described by Gunnar Farneback can be found at |
222 | | opencv_source_code/samples/cpp/fback.cpp |
223 | | - (Python) An example using the optical flow algorithm described by Gunnar Farneback can be |
224 | | found at opencv_source_code/samples/python/opt_flow.py |
225 | | */ |
226 | | CV_EXPORTS_W void calcOpticalFlowFarneback( InputArray prev, InputArray next, InputOutputArray flow, |
227 | | double pyr_scale, int levels, int winsize, |
228 | | int iterations, int poly_n, double poly_sigma, |
229 | | int flags ); |
230 | | |
231 | | /** @brief Computes an optimal affine transformation between two 2D point sets. |
232 | | |
233 | | @param src First input 2D point set stored in std::vector or Mat, or an image stored in Mat. |
234 | | @param dst Second input 2D point set of the same size and the same type as A, or another image. |
235 | | @param fullAffine If true, the function finds an optimal affine transformation with no additional |
236 | | restrictions (6 degrees of freedom). Otherwise, the class of transformations to choose from is |
237 | | limited to combinations of translation, rotation, and uniform scaling (4 degrees of freedom). |
238 | | |
239 | | The function finds an optimal affine transform *[A|b]* (a 2 x 3 floating-point matrix) that |
240 | | approximates best the affine transformation between: |
241 | | |
242 | | * Two point sets |
243 | | * Two raster images. In this case, the function first finds some features in the src image and |
244 | | finds the corresponding features in dst image. After that, the problem is reduced to the first |
245 | | case. |
246 | | In case of point sets, the problem is formulated as follows: you need to find a 2x2 matrix *A* and |
247 | | 2x1 vector *b* so that: |
248 | | |
249 | | \f[[A^*|b^*] = arg \min _{[A|b]} \sum _i \| \texttt{dst}[i] - A { \texttt{src}[i]}^T - b \| ^2\f] |
250 | | where src[i] and dst[i] are the i-th points in src and dst, respectively |
251 | | \f$[A|b]\f$ can be either arbitrary (when fullAffine=true ) or have a form of |
252 | | \f[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ -a_{12} & a_{11} & b_2 \end{bmatrix}\f] |
253 | | when fullAffine=false. |
254 | | |
255 | | @deprecated Use cv::estimateAffine2D, cv::estimateAffinePartial2D instead. If you are using this function |
256 | | with images, extract points using cv::calcOpticalFlowPyrLK and then use the estimation functions. |
257 | | |
258 | | @sa |
259 | | estimateAffine2D, estimateAffinePartial2D, getAffineTransform, getPerspectiveTransform, findHomography |
260 | | */ |
261 | | CV_DEPRECATED CV_EXPORTS Mat estimateRigidTransform( InputArray src, InputArray dst, bool fullAffine ); |
262 | | |
263 | | enum |
264 | | { |
265 | | MOTION_TRANSLATION = 0, |
266 | | MOTION_EUCLIDEAN = 1, |
267 | | MOTION_AFFINE = 2, |
268 | | MOTION_HOMOGRAPHY = 3 |
269 | | }; |
270 | | |
271 | | /** |
272 | | @brief Computes the Enhanced Correlation Coefficient (ECC) value between two images |
273 | | |
274 | | The Enhanced Correlation Coefficient (ECC) is a normalized measure of similarity between two images @cite EP08. |
275 | | The result lies in the range [-1, 1], where 1 corresponds to perfect similarity (modulo affine shift and scale), |
276 | | 0 indicates no correlation, and -1 indicates perfect negative correlation. |
277 | | |
278 | | For single-channel images, the ECC is defined as: |
279 | | |
280 | | \f[ |
281 | | \mathrm{ECC}(I, T) = \frac{\sum_{x} (I(x) - \mu_I)(T(x) - \mu_T)} |
282 | | {\sqrt{\sum_{x} (I(x) - \mu_I)^2} \cdot \sqrt{\sum_{x} (T(x) - \mu_T)^2}} |
283 | | \f] |
284 | | |
285 | | For multi-channel images (e.g., 3-channel RGB), the formula generalizes to: |
286 | | |
287 | | \f[ |
288 | | \mathrm{ECC}(I, T) = |
289 | | \frac{\sum_{x} \sum_{c=1}^{C} (I_c(x) - \mu_{I_c})(T_c(x) - \mu_{T_c})} |
290 | | {\sqrt{\sum_{x} \sum_{c=1}^{C} (I_c(x) - \mu_{I_c})^2} \cdot |
291 | | \sqrt{\sum_{x} \sum_{c=1}^{C} (T_c(x) - \mu_{T_c})^2}} |
292 | | \f] |
293 | | |
294 | | Where: |
295 | | - \f$I_c(x), T_c(x)\f$ are the values of channel \f$c\f$ at spatial location \f$x\f$, |
296 | | - \f$\mu_{I_c}, \mu_{T_c}\f$ are the mean values of channel \f$c\f$ over the masked region (if provided), |
297 | | - \f$C\f$ is the number of channels (only 1 and 3 are currently supported), |
298 | | - The sums run over all pixels \f$x\f$ in the image domain (optionally restricted by mask). |
299 | | |
300 | | @param templateImage Input template image; must have either 1 or 3 channels and be of type CV_8U, CV_16U, CV_32F, or CV_64F. |
301 | | @param inputImage Input image to be compared with the template; must have the same type and number of channels as templateImage. |
302 | | @param inputMask Optional single-channel mask to specify the valid region of interest in inputImage and templateImage. |
303 | | |
304 | | @return The ECC similarity coefficient in the range [-1, 1]. |
305 | | |
306 | | @sa findTransformECC |
307 | | */ |
308 | | CV_EXPORTS_W double computeECC(InputArray templateImage, InputArray inputImage, InputArray inputMask = noArray()); |
309 | | |
310 | | /** @example samples/cpp/image_alignment.cpp |
311 | | An example using the image alignment ECC algorithm |
312 | | */ |
313 | | |
314 | | /** @brief Finds the geometric transform (warp) between two images in terms of the ECC criterion @cite EP08 . |
315 | | |
316 | | @param templateImage 1 or 3 channel template image; CV_8U, CV_16U, CV_32F, CV_64F type. |
317 | | @param inputImage input image which should be warped with the final warpMatrix in |
318 | | order to provide an image similar to templateImage, same type as templateImage. |
319 | | @param warpMatrix floating-point \f$2\times 3\f$ or \f$3\times 3\f$ mapping matrix (warp). |
320 | | @param motionType parameter, specifying the type of motion: |
321 | | - **MOTION_TRANSLATION** sets a translational motion model; warpMatrix is \f$2\times 3\f$ with |
322 | | the first \f$2\times 2\f$ part being the unity matrix and the rest two parameters being |
323 | | estimated. |
324 | | - **MOTION_EUCLIDEAN** sets a Euclidean (rigid) transformation as motion model; three |
325 | | parameters are estimated; warpMatrix is \f$2\times 3\f$. |
326 | | - **MOTION_AFFINE** sets an affine motion model (DEFAULT); six parameters are estimated; |
327 | | warpMatrix is \f$2\times 3\f$. |
328 | | - **MOTION_HOMOGRAPHY** sets a homography as a motion model; eight parameters are |
329 | | estimated;\`warpMatrix\` is \f$3\times 3\f$. |
330 | | @param criteria parameter, specifying the termination criteria of the ECC algorithm; |
331 | | criteria.epsilon defines the threshold of the increment in the correlation coefficient between two |
332 | | iterations (a negative criteria.epsilon makes criteria.maxcount the only termination criterion). |
333 | | Default values are shown in the declaration above. |
334 | | @param inputMask An optional single channel mask to indicate valid values of inputImage. |
335 | | @param gaussFiltSize An optional value indicating size of gaussian blur filter; (DEFAULT: 5) |
336 | | |
337 | | The function estimates the optimum transformation (warpMatrix) with respect to ECC criterion |
338 | | (@cite EP08), that is |
339 | | |
340 | | \f[\texttt{warpMatrix} = \arg\max_{W} \texttt{ECC}(\texttt{templateImage}(x,y),\texttt{inputImage}(x',y'))\f] |
341 | | |
342 | | where |
343 | | |
344 | | \f[\begin{bmatrix} x' \\ y' \end{bmatrix} = W \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}\f] |
345 | | |
346 | | (the equation holds with homogeneous coordinates for homography). It returns the final enhanced |
347 | | correlation coefficient, that is the correlation coefficient between the template image and the |
348 | | final warped input image. When a \f$3\times 3\f$ matrix is given with motionType =0, 1 or 2, the third |
349 | | row is ignored. |
350 | | |
351 | | Unlike findHomography and estimateRigidTransform, the function findTransformECC implements an |
352 | | area-based alignment that builds on intensity similarities. In essence, the function updates the |
353 | | initial transformation that roughly aligns the images. If this information is missing, the identity |
354 | | warp (unity matrix) is used as an initialization. Note that if images undergo strong |
355 | | displacements/rotations, an initial transformation that roughly aligns the images is necessary |
356 | | (e.g., a simple euclidean/similarity transform that allows for the images showing the same image |
357 | | content approximately). Use inverse warping in the second image to take an image close to the first |
358 | | one, i.e. use the flag WARP_INVERSE_MAP with warpAffine or warpPerspective. See also the OpenCV |
359 | | sample image_alignment.cpp that demonstrates the use of the function. Note that the function throws |
360 | | an exception if algorithm does not converges. |
361 | | |
362 | | @sa |
363 | | computeECC, estimateAffine2D, estimateAffinePartial2D, findHomography |
364 | | */ |
365 | | CV_EXPORTS_W double findTransformECC( InputArray templateImage, InputArray inputImage, |
366 | | InputOutputArray warpMatrix, int motionType, |
367 | | TermCriteria criteria, |
368 | | InputArray inputMask, int gaussFiltSize); |
369 | | |
370 | | /** @overload */ |
371 | | CV_EXPORTS_W |
372 | | double findTransformECC(InputArray templateImage, InputArray inputImage, |
373 | | InputOutputArray warpMatrix, int motionType = MOTION_AFFINE, |
374 | | TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001), |
375 | | InputArray inputMask = noArray()); |
376 | | |
377 | | /** @brief Finds the geometric transform (warp) between two images in terms of the ECC criterion @cite EP08 |
378 | | using validity masks for both the template and the input images. |
379 | | |
380 | | This function extends findTransformECC() by adding a mask for the template image. |
381 | | The Enhanced Correlation Coefficient is evaluated only over pixels that are valid in both images: |
382 | | on each iteration inputMask is warped into the template frame and combined with templateMask, and |
383 | | only the intersection of these masks contributes to the objective function. |
384 | | |
385 | | @param templateImage 1 or 3 channel template image; CV_8U, CV_16U, CV_32F, CV_64F type. |
386 | | @param inputImage input image which should be warped with the final warpMatrix in |
387 | | order to provide an image similar to templateImage, same type as templateImage. |
388 | | @param templateMask single-channel 8-bit mask for templateImage indicating valid pixels |
389 | | to be used in the alignment. Must have the same size as templateImage. |
390 | | @param inputMask single-channel 8-bit mask for inputImage indicating valid pixels |
391 | | before warping. Must have the same size as inputImage. |
392 | | @param warpMatrix floating-point \f$2\times 3\f$ or \f$3\times 3\f$ mapping matrix (warp). |
393 | | @param motionType parameter, specifying the type of motion: |
394 | | - **MOTION_TRANSLATION** sets a translational motion model; warpMatrix is \f$2\times 3\f$ with |
395 | | the first \f$2\times 2\f$ part being the unity matrix and the rest two parameters being |
396 | | estimated. |
397 | | - **MOTION_EUCLIDEAN** sets a Euclidean (rigid) transformation as motion model; three |
398 | | parameters are estimated; warpMatrix is \f$2\times 3\f$. |
399 | | - **MOTION_AFFINE** sets an affine motion model (DEFAULT); six parameters are estimated; |
400 | | warpMatrix is \f$2\times 3\f$. |
401 | | - **MOTION_HOMOGRAPHY** sets a homography as a motion model; eight parameters are |
402 | | estimated; warpMatrix is \f$3\times 3\f$. |
403 | | @param criteria parameter, specifying the termination criteria of the ECC algorithm; |
404 | | criteria.epsilon defines the threshold of the increment in the correlation coefficient between two |
405 | | iterations (a negative criteria.epsilon makes criteria.maxcount the only termination criterion). |
406 | | Default values are shown in the declaration above. |
407 | | @param gaussFiltSize size of the Gaussian blur filter used for smoothing images and masks |
408 | | before computing the alignment (DEFAULT: 5). |
409 | | |
410 | | @sa |
411 | | findTransformECC, computeECC, estimateAffine2D, estimateAffinePartial2D, findHomography |
412 | | */ |
413 | | CV_EXPORTS_W double findTransformECCWithMask( InputArray templateImage, |
414 | | InputArray inputImage, |
415 | | InputArray templateMask, |
416 | | InputArray inputMask, |
417 | | InputOutputArray warpMatrix, |
418 | | int motionType = MOTION_AFFINE, |
419 | | TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 50, 1e-6), |
420 | | int gaussFiltSize = 5 ); |
421 | | |
422 | | /** @brief struct ECCParameters is used by findTransformECCMultiScale |
423 | | |
424 | | @param motionType parameter, specifying the type of motion: |
425 | | - **MOTION_TRANSLATION** sets a translational motion model; warpMatrix is \f$2\times 3\f$ with |
426 | | the first \f$2\times 2\f$ part being the unity matrix and the rest two parameters being |
427 | | estimated. |
428 | | - **MOTION_EUCLIDEAN** sets a Euclidean (rigid) transformation as motion model; three |
429 | | parameters are estimated; warpMatrix is \f$2\times 3\f$. |
430 | | - **MOTION_AFFINE** sets an affine motion model (DEFAULT); six parameters are estimated; |
431 | | warpMatrix is \f$2\times 3\f$. |
432 | | - **MOTION_HOMOGRAPHY** sets a homography as a motion model; eight parameters are |
433 | | estimated;\`warpMatrix\` is \f$3\times 3\f$. |
434 | | @param criteria parameter, specifying the termination criteria of the ECC algorithm; |
435 | | criteria.epsilon defines the threshold of the increment in the correlation coefficient between two |
436 | | iterations (a negative criteria.epsilon makes criteria.maxcount the only termination criterion). |
437 | | Default values are shown in the declaration above. |
438 | | @param itersPerLevel Criterion extension: distribution of iterations limit over pyramid levels. |
439 | | Can be empty, in this case, this algorithm will use criteria.maxCount on each level. |
440 | | @param gaussFiltSize An optional value indicating size of gaussian blur filter; (DEFAULT: 5) |
441 | | @param nlevels An optional value indicating amount of levels in the pyramid; (DEFAULT: 4) |
442 | | @param interpolation Type of warp interpolation. Possible values are INTER_NEAREST and INTER_LINEAR. |
443 | | Affects accuracy, especially when motionType == MOTION_TRANSLATION. (DEFAULT: INTER_LINEAR) |
444 | | */ |
445 | | struct CV_EXPORTS_W_SIMPLE ECCParameters |
446 | | { |
447 | 0 | CV_WRAP ECCParameters() {} |
448 | | CV_PROP_RW int motionType = MOTION_AFFINE; |
449 | | CV_PROP_RW cv::TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 50, 1e-6); |
450 | | CV_PROP_RW std::vector<int> itersPerLevel = std::vector<int>(); |
451 | | CV_PROP_RW int gaussFiltSize = 5; |
452 | | CV_PROP_RW int nlevels = 4; |
453 | | CV_PROP_RW int interpolation = INTER_LINEAR; |
454 | | }; |
455 | | |
456 | | /** @brief Finds the geometric transform (warp) between two images in terms of the ECC criterion @cite EP08. Uses pyramids. |
457 | | |
458 | | @param reference Single channel reference image; CV_8U, CV_16U, CV_32F, CV_64F type. |
459 | | @param sample sample image which should be warped with the final warpMatrix in |
460 | | order to provide an image similar to reference, same type as reference. |
461 | | @param warpMatrix floating-point \f$2\times 3\f$ or \f$3\times 3\f$ mapping matrix (warp). |
462 | | @param eccParams List of the algorithm parameters. See ECCParameters for details. |
463 | | @param referenceMask An optional single channel mask to indicate valid values of reference. |
464 | | @param sampleMask An optional single channel mask to indicate valid values of sample. |
465 | | |
466 | | The function estimates the optimum transformation (warpMatrix) with respect to ECC criterion |
467 | | (@cite EP08), that is |
468 | | |
469 | | \f[\texttt{warpMatrix} = \arg\max_{W} \texttt{ECC}(\texttt{templateImage}(x,y),\texttt{inputImage}(x',y'))\f] |
470 | | |
471 | | where |
472 | | |
473 | | \f[\begin{bmatrix} x' \\ y' \end{bmatrix} = W \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}\f] |
474 | | |
475 | | (the equation holds with homogeneous coordinates for homography). It returns the final enhanced |
476 | | correlation coefficient, that is the correlation coefficient between the template image and the |
477 | | final warped input image. When a \f$3\times 3\f$ matrix is given with motionType =0, 1 or 2, the third |
478 | | row is ignored. |
479 | | |
480 | | Unlike findHomography and estimateRigidTransform, the function findTransformECCMultiScale implements |
481 | | an area-based alignment that builds on intensity similarities. In essence, the function updates the |
482 | | initial transformation that roughly aligns the images. If this information is missing, the identity |
483 | | warp (unity matrix) is used as an initialization. Note that if images undergo strong |
484 | | displacements/rotations, an initial transformation that roughly aligns the images is necessary |
485 | | (e.g., a simple euclidean/similarity transform that allows for the images showing the same image |
486 | | content approximately). Use inverse warping in the second image to take an image close to the first |
487 | | one, i.e. use the flag WARP_INVERSE_MAP with warpAffine or warpPerspective. See also the OpenCV |
488 | | sample image_alignment.cpp that demonstrates the use of the function. Note that the function throws |
489 | | an exception if algorithm does not converges. |
490 | | Unlike findTransformECC, the findTransformECCMultiScale uses pyramids, making function more stable |
491 | | and able to handle correctly more sophisticated cases. |
492 | | |
493 | | @sa |
494 | | computeECC, estimateAffine2D, estimateAffinePartial2D, findHomography |
495 | | */ |
496 | | |
497 | | CV_EXPORTS_W double findTransformECCMultiScale(InputArray reference, |
498 | | InputArray sample, |
499 | | InputOutputArray warpMatrix, |
500 | | const ECCParameters& eccParams = ECCParameters(), |
501 | | InputArray referenceMask = noArray(), |
502 | | InputArray sampleMask = noArray()); |
503 | | |
504 | | /** @example samples/cpp/kalman.cpp |
505 | | An example using the standard Kalman filter |
506 | | */ |
507 | | |
508 | | /** @brief Kalman filter class. |
509 | | |
510 | | The class implements a standard Kalman filter <http://en.wikipedia.org/wiki/Kalman_filter>, |
511 | | @cite Welch95 . However, you can modify transitionMatrix, controlMatrix, and measurementMatrix to get |
512 | | an extended Kalman filter functionality. |
513 | | @note In C API when CvKalman\* kalmanFilter structure is not needed anymore, it should be released |
514 | | with cvReleaseKalman(&kalmanFilter) |
515 | | */ |
516 | | class CV_EXPORTS_W KalmanFilter |
517 | | { |
518 | | public: |
519 | | CV_WRAP KalmanFilter(); |
520 | | /** @overload |
521 | | @param dynamParams Dimensionality of the state. |
522 | | @param measureParams Dimensionality of the measurement. |
523 | | @param controlParams Dimensionality of the control vector. |
524 | | @param type Type of the created matrices that should be CV_32F or CV_64F. |
525 | | */ |
526 | | CV_WRAP KalmanFilter( int dynamParams, int measureParams, int controlParams = 0, int type = CV_32F ); |
527 | | |
528 | | /** @brief Re-initializes Kalman filter. The previous content is destroyed. |
529 | | |
530 | | @param dynamParams Dimensionality of the state. |
531 | | @param measureParams Dimensionality of the measurement. |
532 | | @param controlParams Dimensionality of the control vector. |
533 | | @param type Type of the created matrices that should be CV_32F or CV_64F. |
534 | | */ |
535 | | void init( int dynamParams, int measureParams, int controlParams = 0, int type = CV_32F ); |
536 | | |
537 | | /** @brief Computes a predicted state. |
538 | | |
539 | | @param control The optional input control |
540 | | */ |
541 | | CV_WRAP const Mat& predict( const Mat& control = Mat() ); |
542 | | |
543 | | /** @brief Updates the predicted state from the measurement. |
544 | | |
545 | | @param measurement The measured system parameters |
546 | | */ |
547 | | CV_WRAP const Mat& correct( const Mat& measurement ); |
548 | | |
549 | | CV_PROP_RW Mat statePre; //!< predicted state (x'(k)): x(k)=A*x(k-1)+B*u(k) |
550 | | CV_PROP_RW Mat statePost; //!< corrected state (x(k)): x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) |
551 | | CV_PROP_RW Mat transitionMatrix; //!< state transition matrix (A) |
552 | | CV_PROP_RW Mat controlMatrix; //!< control matrix (B) (not used if there is no control) |
553 | | CV_PROP_RW Mat measurementMatrix; //!< measurement matrix (H) |
554 | | CV_PROP_RW Mat processNoiseCov; //!< process noise covariance matrix (Q) |
555 | | CV_PROP_RW Mat measurementNoiseCov;//!< measurement noise covariance matrix (R) |
556 | | CV_PROP_RW Mat errorCovPre; //!< priori error estimate covariance matrix (P'(k)): P'(k)=A*P(k-1)*At + Q)*/ |
557 | | CV_PROP_RW Mat gain; //!< Kalman gain matrix (K(k)): K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R) |
558 | | CV_PROP_RW Mat errorCovPost; //!< posteriori error estimate covariance matrix (P(k)): P(k)=(I-K(k)*H)*P'(k) |
559 | | |
560 | | // temporary matrices |
561 | | Mat temp1; |
562 | | Mat temp2; |
563 | | Mat temp3; |
564 | | Mat temp4; |
565 | | Mat temp5; |
566 | | }; |
567 | | |
568 | | |
569 | | /** @brief Read a .flo file |
570 | | |
571 | | @param path Path to the file to be loaded |
572 | | |
573 | | The function readOpticalFlow loads a flow field from a file and returns it as a single matrix. |
574 | | Resulting Mat has a type CV_32FC2 - floating-point, 2-channel. First channel corresponds to the |
575 | | flow in the horizontal direction (u), second - vertical (v). |
576 | | */ |
577 | | CV_EXPORTS_W Mat readOpticalFlow( const String& path ); |
578 | | /** @brief Write a .flo to disk |
579 | | |
580 | | @param path Path to the file to be written |
581 | | @param flow Flow field to be stored |
582 | | |
583 | | The function stores a flow field in a file, returns true on success, false otherwise. |
584 | | The flow field must be a 2-channel, floating-point matrix (CV_32FC2). First channel corresponds |
585 | | to the flow in the horizontal direction (u), second - vertical (v). |
586 | | */ |
587 | | CV_EXPORTS_W bool writeOpticalFlow( const String& path, InputArray flow ); |
588 | | |
589 | | /** |
590 | | Base class for dense optical flow algorithms |
591 | | */ |
592 | | class CV_EXPORTS_W DenseOpticalFlow : public Algorithm |
593 | | { |
594 | | public: |
595 | | /** @brief Calculates an optical flow. |
596 | | |
597 | | @param I0 first 8-bit single-channel input image. |
598 | | @param I1 second input image of the same size and the same type as prev. |
599 | | @param flow computed flow image that has the same size as prev and type CV_32FC2. |
600 | | */ |
601 | | CV_WRAP virtual void calc( InputArray I0, InputArray I1, InputOutputArray flow ) = 0; |
602 | | /** @brief Releases all inner buffers. |
603 | | */ |
604 | | CV_WRAP virtual void collectGarbage() = 0; |
605 | | }; |
606 | | |
607 | | /** @brief Base interface for sparse optical flow algorithms. |
608 | | */ |
609 | | class CV_EXPORTS_W SparseOpticalFlow : public Algorithm |
610 | | { |
611 | | public: |
612 | | /** @brief Calculates a sparse optical flow. |
613 | | |
614 | | @param prevImg First input image. |
615 | | @param nextImg Second input image of the same size and the same type as prevImg. |
616 | | @param prevPts Vector of 2D points for which the flow needs to be found. |
617 | | @param nextPts Output vector of 2D points containing the calculated new positions of input features in the second image. |
618 | | @param status Output status vector. Each element of the vector is set to 1 if the |
619 | | flow for the corresponding features has been found. Otherwise, it is set to 0. |
620 | | @param err Optional output vector that contains error response for each point (inverse confidence). |
621 | | */ |
622 | | CV_WRAP virtual void calc(InputArray prevImg, InputArray nextImg, |
623 | | InputArray prevPts, InputOutputArray nextPts, |
624 | | OutputArray status, |
625 | | OutputArray err = cv::noArray()) = 0; |
626 | | }; |
627 | | |
628 | | |
629 | | /** @brief Class computing a dense optical flow using the Gunnar Farneback's algorithm. |
630 | | */ |
631 | | class CV_EXPORTS_W FarnebackOpticalFlow : public DenseOpticalFlow |
632 | | { |
633 | | public: |
634 | | CV_WRAP virtual int getNumLevels() const = 0; |
635 | | CV_WRAP virtual void setNumLevels(int numLevels) = 0; |
636 | | |
637 | | CV_WRAP virtual double getPyrScale() const = 0; |
638 | | CV_WRAP virtual void setPyrScale(double pyrScale) = 0; |
639 | | |
640 | | CV_WRAP virtual bool getFastPyramids() const = 0; |
641 | | CV_WRAP virtual void setFastPyramids(bool fastPyramids) = 0; |
642 | | |
643 | | CV_WRAP virtual int getWinSize() const = 0; |
644 | | CV_WRAP virtual void setWinSize(int winSize) = 0; |
645 | | |
646 | | CV_WRAP virtual int getNumIters() const = 0; |
647 | | CV_WRAP virtual void setNumIters(int numIters) = 0; |
648 | | |
649 | | CV_WRAP virtual int getPolyN() const = 0; |
650 | | CV_WRAP virtual void setPolyN(int polyN) = 0; |
651 | | |
652 | | CV_WRAP virtual double getPolySigma() const = 0; |
653 | | CV_WRAP virtual void setPolySigma(double polySigma) = 0; |
654 | | |
655 | | CV_WRAP virtual int getFlags() const = 0; |
656 | | CV_WRAP virtual void setFlags(int flags) = 0; |
657 | | |
658 | | CV_WRAP static Ptr<FarnebackOpticalFlow> create( |
659 | | int numLevels = 5, |
660 | | double pyrScale = 0.5, |
661 | | bool fastPyramids = false, |
662 | | int winSize = 13, |
663 | | int numIters = 10, |
664 | | int polyN = 5, |
665 | | double polySigma = 1.1, |
666 | | int flags = 0); |
667 | | }; |
668 | | |
669 | | /** @brief Variational optical flow refinement |
670 | | |
671 | | This class implements variational refinement of the input flow field, i.e. |
672 | | it uses input flow to initialize the minimization of the following functional: |
673 | | \f$E(U) = \int_{\Omega} \delta \Psi(E_I) + \gamma \Psi(E_G) + \alpha \Psi(E_S) \f$, |
674 | | where \f$E_I,E_G,E_S\f$ are color constancy, gradient constancy and smoothness terms |
675 | | respectively. \f$\Psi(s^2)=\sqrt{s^2+\epsilon^2}\f$ is a robust penalizer to limit the |
676 | | influence of outliers. A complete formulation and a description of the minimization |
677 | | procedure can be found in @cite Brox2004 |
678 | | */ |
679 | | class CV_EXPORTS_W VariationalRefinement : public DenseOpticalFlow |
680 | | { |
681 | | public: |
682 | | /** @brief @ref calc function overload to handle separate horizontal (u) and vertical (v) flow components |
683 | | (to avoid extra splits/merges) */ |
684 | | CV_WRAP virtual void calcUV(InputArray I0, InputArray I1, InputOutputArray flow_u, InputOutputArray flow_v) = 0; |
685 | | |
686 | | /** @brief Number of outer (fixed-point) iterations in the minimization procedure. |
687 | | @see setFixedPointIterations */ |
688 | | CV_WRAP virtual int getFixedPointIterations() const = 0; |
689 | | /** @copybrief getFixedPointIterations @see getFixedPointIterations */ |
690 | | CV_WRAP virtual void setFixedPointIterations(int val) = 0; |
691 | | |
692 | | /** @brief Number of inner successive over-relaxation (SOR) iterations |
693 | | in the minimization procedure to solve the respective linear system. |
694 | | @see setSorIterations */ |
695 | | CV_WRAP virtual int getSorIterations() const = 0; |
696 | | /** @copybrief getSorIterations @see getSorIterations */ |
697 | | CV_WRAP virtual void setSorIterations(int val) = 0; |
698 | | |
699 | | /** @brief Relaxation factor in SOR |
700 | | @see setOmega */ |
701 | | CV_WRAP virtual float getOmega() const = 0; |
702 | | /** @copybrief getOmega @see getOmega */ |
703 | | CV_WRAP virtual void setOmega(float val) = 0; |
704 | | |
705 | | /** @brief Weight of the smoothness term |
706 | | @see setAlpha */ |
707 | | CV_WRAP virtual float getAlpha() const = 0; |
708 | | /** @copybrief getAlpha @see getAlpha */ |
709 | | CV_WRAP virtual void setAlpha(float val) = 0; |
710 | | |
711 | | /** @brief Weight of the color constancy term |
712 | | @see setDelta */ |
713 | | CV_WRAP virtual float getDelta() const = 0; |
714 | | /** @copybrief getDelta @see getDelta */ |
715 | | CV_WRAP virtual void setDelta(float val) = 0; |
716 | | |
717 | | /** @brief Weight of the gradient constancy term |
718 | | @see setGamma */ |
719 | | CV_WRAP virtual float getGamma() const = 0; |
720 | | /** @copybrief getGamma @see getGamma */ |
721 | | CV_WRAP virtual void setGamma(float val) = 0; |
722 | | |
723 | | /** @brief Norm value shift for robust penalizer |
724 | | @see setEpsilon */ |
725 | | CV_WRAP virtual float getEpsilon() const = 0; |
726 | | /** @copybrief getEpsilon @see getEpsilon */ |
727 | | CV_WRAP virtual void setEpsilon(float val) = 0; |
728 | | |
729 | | /** @brief Creates an instance of VariationalRefinement |
730 | | */ |
731 | | CV_WRAP static Ptr<VariationalRefinement> create(); |
732 | | }; |
733 | | |
734 | | /** @brief DIS optical flow algorithm. |
735 | | |
736 | | This class implements the Dense Inverse Search (DIS) optical flow algorithm. More |
737 | | details about the algorithm can be found at @cite Kroeger2016 . Includes three presets with preselected |
738 | | parameters to provide reasonable trade-off between speed and quality. However, even the slowest preset is |
739 | | still relatively fast, use DeepFlow if you need better quality and don't care about speed. |
740 | | |
741 | | This implementation includes several additional features compared to the algorithm described in the paper, |
742 | | including spatial propagation of flow vectors (@ref getUseSpatialPropagation), as well as an option to |
743 | | utilize an initial flow approximation passed to @ref calc (which is, essentially, temporal propagation, |
744 | | if the previous frame's flow field is passed). |
745 | | */ |
746 | | class CV_EXPORTS_W DISOpticalFlow : public DenseOpticalFlow |
747 | | { |
748 | | public: |
749 | | enum |
750 | | { |
751 | | PRESET_ULTRAFAST = 0, |
752 | | PRESET_FAST = 1, |
753 | | PRESET_MEDIUM = 2 |
754 | | }; |
755 | | |
756 | | /** @brief Finest level of the Gaussian pyramid on which the flow is computed (zero level |
757 | | corresponds to the original image resolution). The final flow is obtained by bilinear upscaling. |
758 | | @see setFinestScale */ |
759 | | CV_WRAP virtual int getFinestScale() const = 0; |
760 | | /** @copybrief getFinestScale @see getFinestScale */ |
761 | | CV_WRAP virtual void setFinestScale(int val) = 0; |
762 | | |
763 | | /** @brief Sets the coarsest scale |
764 | | @param val Coarsest level of the Gaussian pyramid on which the flow is computed. |
765 | | If set to -1, the auto-computed coarsest scale will be used. |
766 | | */ |
767 | | CV_WRAP virtual void setCoarsestScale(int val) = 0; |
768 | | |
769 | | /** @brief Gets the coarsest scale |
770 | | */ |
771 | | CV_WRAP virtual int getCoarsestScale() const = 0; |
772 | | |
773 | | /** @brief Size of an image patch for matching (in pixels). Normally, default 8x8 patches work well |
774 | | enough in most cases. |
775 | | @see setPatchSize */ |
776 | | CV_WRAP virtual int getPatchSize() const = 0; |
777 | | /** @copybrief getPatchSize @see getPatchSize */ |
778 | | CV_WRAP virtual void setPatchSize(int val) = 0; |
779 | | |
780 | | /** @brief Stride between neighbor patches. Must be less than patch size. Lower values correspond |
781 | | to higher flow quality. |
782 | | @see setPatchStride */ |
783 | | CV_WRAP virtual int getPatchStride() const = 0; |
784 | | /** @copybrief getPatchStride @see getPatchStride */ |
785 | | CV_WRAP virtual void setPatchStride(int val) = 0; |
786 | | |
787 | | /** @brief Maximum number of gradient descent iterations in the patch inverse search stage. Higher values |
788 | | may improve quality in some cases. |
789 | | @see setGradientDescentIterations */ |
790 | | CV_WRAP virtual int getGradientDescentIterations() const = 0; |
791 | | /** @copybrief getGradientDescentIterations @see getGradientDescentIterations */ |
792 | | CV_WRAP virtual void setGradientDescentIterations(int val) = 0; |
793 | | |
794 | | /** @brief Number of fixed point iterations of variational refinement per scale. Set to zero to |
795 | | disable variational refinement completely. Higher values will typically result in more smooth and |
796 | | high-quality flow. |
797 | | @see setGradientDescentIterations */ |
798 | | CV_WRAP virtual int getVariationalRefinementIterations() const = 0; |
799 | | /** @copybrief getGradientDescentIterations @see getGradientDescentIterations */ |
800 | | CV_WRAP virtual void setVariationalRefinementIterations(int val) = 0; |
801 | | |
802 | | /** @brief Weight of the smoothness term |
803 | | @see setVariationalRefinementAlpha */ |
804 | | CV_WRAP virtual float getVariationalRefinementAlpha() const = 0; |
805 | | /** @copybrief getVariationalRefinementAlpha @see getVariationalRefinementAlpha */ |
806 | | CV_WRAP virtual void setVariationalRefinementAlpha(float val) = 0; |
807 | | |
808 | | /** @brief Weight of the color constancy term |
809 | | @see setVariationalRefinementDelta */ |
810 | | CV_WRAP virtual float getVariationalRefinementDelta() const = 0; |
811 | | /** @copybrief getVariationalRefinementDelta @see getVariationalRefinementDelta */ |
812 | | CV_WRAP virtual void setVariationalRefinementDelta(float val) = 0; |
813 | | |
814 | | /** @brief Weight of the gradient constancy term |
815 | | @see setVariationalRefinementGamma */ |
816 | | CV_WRAP virtual float getVariationalRefinementGamma() const = 0; |
817 | | /** @copybrief getVariationalRefinementGamma @see getVariationalRefinementGamma */ |
818 | | CV_WRAP virtual void setVariationalRefinementGamma(float val) = 0; |
819 | | |
820 | | /** @brief Norm value shift for robust penalizer |
821 | | @see setVariationalRefinementEpsilon */ |
822 | | CV_WRAP virtual float getVariationalRefinementEpsilon() const = 0; |
823 | | /** @copybrief getVariationalRefinementEpsilon @see getVariationalRefinementEpsilon */ |
824 | | CV_WRAP virtual void setVariationalRefinementEpsilon(float val) = 0; |
825 | | |
826 | | |
827 | | /** @brief Whether to use mean-normalization of patches when computing patch distance. It is turned on |
828 | | by default as it typically provides a noticeable quality boost because of increased robustness to |
829 | | illumination variations. Turn it off if you are certain that your sequence doesn't contain any changes |
830 | | in illumination. |
831 | | @see setUseMeanNormalization */ |
832 | | CV_WRAP virtual bool getUseMeanNormalization() const = 0; |
833 | | /** @copybrief getUseMeanNormalization @see getUseMeanNormalization */ |
834 | | CV_WRAP virtual void setUseMeanNormalization(bool val) = 0; |
835 | | |
836 | | /** @brief Whether to use spatial propagation of good optical flow vectors. This option is turned on by |
837 | | default, as it tends to work better on average and can sometimes help recover from major errors |
838 | | introduced by the coarse-to-fine scheme employed by the DIS optical flow algorithm. Turning this |
839 | | option off can make the output flow field a bit smoother, however. |
840 | | @see setUseSpatialPropagation */ |
841 | | CV_WRAP virtual bool getUseSpatialPropagation() const = 0; |
842 | | /** @copybrief getUseSpatialPropagation @see getUseSpatialPropagation */ |
843 | | CV_WRAP virtual void setUseSpatialPropagation(bool val) = 0; |
844 | | |
845 | | /** @brief Creates an instance of DISOpticalFlow |
846 | | |
847 | | @param preset one of PRESET_ULTRAFAST, PRESET_FAST and PRESET_MEDIUM |
848 | | */ |
849 | | CV_WRAP static Ptr<DISOpticalFlow> create(int preset = DISOpticalFlow::PRESET_FAST); |
850 | | }; |
851 | | |
852 | | /** @brief Class used for calculating a sparse optical flow. |
853 | | |
854 | | The class can calculate an optical flow for a sparse feature set using the |
855 | | iterative Lucas-Kanade method with pyramids. |
856 | | |
857 | | @sa calcOpticalFlowPyrLK |
858 | | |
859 | | */ |
860 | | class CV_EXPORTS_W SparsePyrLKOpticalFlow : public SparseOpticalFlow |
861 | | { |
862 | | public: |
863 | | CV_WRAP virtual Size getWinSize() const = 0; |
864 | | CV_WRAP virtual void setWinSize(Size winSize) = 0; |
865 | | |
866 | | CV_WRAP virtual int getMaxLevel() const = 0; |
867 | | CV_WRAP virtual void setMaxLevel(int maxLevel) = 0; |
868 | | |
869 | | CV_WRAP virtual TermCriteria getTermCriteria() const = 0; |
870 | | CV_WRAP virtual void setTermCriteria(TermCriteria& crit) = 0; |
871 | | |
872 | | CV_WRAP virtual int getFlags() const = 0; |
873 | | CV_WRAP virtual void setFlags(int flags) = 0; |
874 | | |
875 | | CV_WRAP virtual double getMinEigThreshold() const = 0; |
876 | | CV_WRAP virtual void setMinEigThreshold(double minEigThreshold) = 0; |
877 | | |
878 | | CV_WRAP static Ptr<SparsePyrLKOpticalFlow> create( |
879 | | Size winSize = Size(21, 21), |
880 | | int maxLevel = 3, TermCriteria crit = |
881 | | TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), |
882 | | int flags = 0, |
883 | | double minEigThreshold = 1e-4); |
884 | | }; |
885 | | |
886 | | |
887 | | |
888 | | |
889 | | /** @brief Base abstract class for the long-term tracker |
890 | | */ |
891 | | class CV_EXPORTS_W Tracker |
892 | | { |
893 | | protected: |
894 | | Tracker(); |
895 | | public: |
896 | | virtual ~Tracker(); |
897 | | |
898 | | /** @brief Initialize the tracker with a known bounding box that surrounded the target |
899 | | @param image The initial frame |
900 | | @param boundingBox The initial bounding box |
901 | | */ |
902 | | CV_WRAP virtual |
903 | | void init(InputArray image, const Rect& boundingBox) = 0; |
904 | | |
905 | | /** @brief Update the tracker, find the new most likely bounding box for the target |
906 | | @param image The current frame |
907 | | @param boundingBox The bounding box that represent the new target location, if true was returned, not |
908 | | modified otherwise |
909 | | |
910 | | @return True means that target was located and false means that tracker cannot locate target in |
911 | | current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed |
912 | | missing from the frame (say, out of sight) |
913 | | */ |
914 | | CV_WRAP virtual |
915 | | bool update(InputArray image, CV_OUT Rect& boundingBox) = 0; |
916 | | }; |
917 | | |
918 | | |
919 | | |
920 | | /** @brief The MIL algorithm trains a classifier in an online manner to separate the object from the |
921 | | background. |
922 | | |
923 | | Multiple Instance Learning avoids the drift problem for a robust tracking. The implementation is |
924 | | based on @cite MIL . |
925 | | |
926 | | Original code can be found here <http://vision.ucsd.edu/~bbabenko/project_miltrack.shtml> |
927 | | */ |
928 | | class CV_EXPORTS_W TrackerMIL : public Tracker |
929 | | { |
930 | | protected: |
931 | | TrackerMIL(); // use ::create() |
932 | | public: |
933 | | virtual ~TrackerMIL() CV_OVERRIDE; |
934 | | |
935 | | struct CV_EXPORTS_W_SIMPLE Params |
936 | | { |
937 | | CV_WRAP Params(); |
938 | | //parameters for sampler |
939 | | CV_PROP_RW float samplerInitInRadius; //!< radius for gathering positive instances during init |
940 | | CV_PROP_RW int samplerInitMaxNegNum; //!< # negative samples to use during init |
941 | | CV_PROP_RW float samplerSearchWinSize; //!< size of search window |
942 | | CV_PROP_RW float samplerTrackInRadius; //!< radius for gathering positive instances during tracking |
943 | | CV_PROP_RW int samplerTrackMaxPosNum; //!< # positive samples to use during tracking |
944 | | CV_PROP_RW int samplerTrackMaxNegNum; //!< # negative samples to use during tracking |
945 | | CV_PROP_RW int featureSetNumFeatures; //!< # features |
946 | | }; |
947 | | |
948 | | /** @brief Create MIL tracker instance |
949 | | * @param parameters MIL parameters TrackerMIL::Params |
950 | | */ |
951 | | static CV_WRAP |
952 | | Ptr<TrackerMIL> create(const TrackerMIL::Params ¶meters = TrackerMIL::Params()); |
953 | | |
954 | | //void init(InputArray image, const Rect& boundingBox) CV_OVERRIDE; |
955 | | //bool update(InputArray image, CV_OUT Rect& boundingBox) CV_OVERRIDE; |
956 | | }; |
957 | | |
958 | | |
959 | | |
960 | | /** @brief the GOTURN (Generic Object Tracking Using Regression Networks) tracker |
961 | | * |
962 | | * GOTURN (@cite GOTURN) is kind of trackers based on Convolutional Neural Networks (CNN). While taking all advantages of CNN trackers, |
963 | | * GOTURN is much faster due to offline training without online fine-tuning nature. |
964 | | * GOTURN tracker addresses the problem of single target tracking: given a bounding box label of an object in the first frame of the video, |
965 | | * we track that object through the rest of the video. NOTE: Current method of GOTURN does not handle occlusions; however, it is fairly |
966 | | * robust to viewpoint changes, lighting changes, and deformations. |
967 | | * Inputs of GOTURN are two RGB patches representing Target and Search patches resized to 227x227. |
968 | | * Outputs of GOTURN are predicted bounding box coordinates, relative to Search patch coordinate system, in format X1,Y1,X2,Y2. |
969 | | * Original paper is here: <http://davheld.github.io/GOTURN/GOTURN.pdf> |
970 | | * As long as original authors implementation: <https://github.com/davheld/GOTURN#train-the-tracker> |
971 | | * Implementation of training algorithm is placed in separately here due to 3d-party dependencies: |
972 | | * <https://github.com/Auron-X/GOTURN_Training_Toolkit> |
973 | | * GOTURN architecture goturn.prototxt and trained model goturn.caffemodel are accessible on opencv_extra GitHub repository. |
974 | | */ |
975 | | class CV_EXPORTS_W TrackerGOTURN : public Tracker |
976 | | { |
977 | | protected: |
978 | | TrackerGOTURN(); // use ::create() |
979 | | public: |
980 | | virtual ~TrackerGOTURN() CV_OVERRIDE; |
981 | | |
982 | | struct CV_EXPORTS_W_SIMPLE Params |
983 | | { |
984 | | CV_WRAP Params(); |
985 | | CV_PROP_RW std::string modelTxt; |
986 | | CV_PROP_RW std::string modelBin; |
987 | | }; |
988 | | |
989 | | /** @brief Constructor |
990 | | @param parameters GOTURN parameters TrackerGOTURN::Params |
991 | | */ |
992 | | static CV_WRAP |
993 | | Ptr<TrackerGOTURN> create(const TrackerGOTURN::Params& parameters = TrackerGOTURN::Params()); |
994 | | |
995 | | #ifdef HAVE_OPENCV_DNN |
996 | | /** @brief Constructor |
997 | | @param model pre-loaded GOTURN model |
998 | | */ |
999 | | static CV_WRAP Ptr<TrackerGOTURN> create(const dnn::Net& model); |
1000 | | #endif |
1001 | | |
1002 | | //void init(InputArray image, const Rect& boundingBox) CV_OVERRIDE; |
1003 | | //bool update(InputArray image, CV_OUT Rect& boundingBox) CV_OVERRIDE; |
1004 | | }; |
1005 | | |
1006 | | class CV_EXPORTS_W TrackerDaSiamRPN : public Tracker |
1007 | | { |
1008 | | protected: |
1009 | | TrackerDaSiamRPN(); // use ::create() |
1010 | | public: |
1011 | | virtual ~TrackerDaSiamRPN() CV_OVERRIDE; |
1012 | | |
1013 | | struct CV_EXPORTS_W_SIMPLE Params |
1014 | | { |
1015 | | CV_WRAP Params(); |
1016 | | CV_PROP_RW std::string model; |
1017 | | CV_PROP_RW std::string kernel_cls1; |
1018 | | CV_PROP_RW std::string kernel_r1; |
1019 | | CV_PROP_RW int backend; |
1020 | | CV_PROP_RW int target; |
1021 | | }; |
1022 | | |
1023 | | /** @brief Constructor |
1024 | | @param parameters DaSiamRPN parameters TrackerDaSiamRPN::Params |
1025 | | */ |
1026 | | static CV_WRAP |
1027 | | Ptr<TrackerDaSiamRPN> create(const TrackerDaSiamRPN::Params& parameters = TrackerDaSiamRPN::Params()); |
1028 | | |
1029 | | #ifdef HAVE_OPENCV_DNN |
1030 | | /** @brief Constructor |
1031 | | * @param siam_rpn pre-loaded SiamRPN model |
1032 | | * @param kernel_cls1 pre-loaded CLS model |
1033 | | * @param kernel_r1 pre-loaded R1 model |
1034 | | */ |
1035 | | static CV_WRAP |
1036 | | Ptr<TrackerDaSiamRPN> create(const dnn::Net& siam_rpn, const dnn::Net& kernel_cls1, const dnn::Net& kernel_r1); |
1037 | | #endif |
1038 | | |
1039 | | /** @brief Return tracking score |
1040 | | */ |
1041 | | CV_WRAP virtual float getTrackingScore() = 0; |
1042 | | |
1043 | | //void init(InputArray image, const Rect& boundingBox) CV_OVERRIDE; |
1044 | | //bool update(InputArray image, CV_OUT Rect& boundingBox) CV_OVERRIDE; |
1045 | | }; |
1046 | | |
1047 | | /** @brief the Nano tracker is a super lightweight dnn-based general object tracking. |
1048 | | * |
1049 | | * Nano tracker is much faster and extremely lightweight due to special model structure, the whole model size is about 1.9 MB. |
1050 | | * Nano tracker needs two models: one for feature extraction (backbone) and the another for localization (neckhead). |
1051 | | * Model download link: https://github.com/HonglinChu/SiamTrackers/tree/master/NanoTrack/models/nanotrackv2 |
1052 | | * Original repo is here: https://github.com/HonglinChu/NanoTrack |
1053 | | * Author: HongLinChu, 1628464345@qq.com |
1054 | | */ |
1055 | | class CV_EXPORTS_W TrackerNano : public Tracker |
1056 | | { |
1057 | | protected: |
1058 | | TrackerNano(); // use ::create() |
1059 | | public: |
1060 | | virtual ~TrackerNano() CV_OVERRIDE; |
1061 | | |
1062 | | struct CV_EXPORTS_W_SIMPLE Params |
1063 | | { |
1064 | | CV_WRAP Params(); |
1065 | | CV_PROP_RW std::string backbone; |
1066 | | CV_PROP_RW std::string neckhead; |
1067 | | CV_PROP_RW int backend; |
1068 | | CV_PROP_RW int target; |
1069 | | }; |
1070 | | |
1071 | | /** @brief Constructor |
1072 | | @param parameters NanoTrack parameters TrackerNano::Params |
1073 | | */ |
1074 | | static CV_WRAP |
1075 | | Ptr<TrackerNano> create(const TrackerNano::Params& parameters = TrackerNano::Params()); |
1076 | | |
1077 | | #ifdef HAVE_OPENCV_DNN |
1078 | | /** @brief Constructor |
1079 | | * @param backbone pre-loaded backbone model |
1080 | | * @param neckhead pre-loaded neckhead model |
1081 | | */ |
1082 | | static CV_WRAP |
1083 | | Ptr<TrackerNano> create(const dnn::Net& backbone, const dnn::Net& neckhead); |
1084 | | #endif |
1085 | | |
1086 | | /** @brief Return tracking score |
1087 | | */ |
1088 | | CV_WRAP virtual float getTrackingScore() = 0; |
1089 | | |
1090 | | //void init(InputArray image, const Rect& boundingBox) CV_OVERRIDE; |
1091 | | //bool update(InputArray image, CV_OUT Rect& boundingBox) CV_OVERRIDE; |
1092 | | }; |
1093 | | |
1094 | | /** @brief the VIT tracker is a super lightweight dnn-based general object tracking. |
1095 | | * |
1096 | | * VIT tracker is much faster and extremely lightweight due to special model structure, the model file is about 767KB. |
1097 | | * Model download link: https://github.com/opencv/opencv_zoo/tree/main/models/object_tracking_vittrack |
1098 | | * Author: PengyuLiu, 1872918507@qq.com |
1099 | | */ |
1100 | | class CV_EXPORTS_W TrackerVit : public Tracker |
1101 | | { |
1102 | | protected: |
1103 | | TrackerVit(); // use ::create() |
1104 | | public: |
1105 | | virtual ~TrackerVit() CV_OVERRIDE; |
1106 | | |
1107 | | struct CV_EXPORTS_W_SIMPLE Params |
1108 | | { |
1109 | | CV_WRAP Params(); |
1110 | | CV_PROP_RW std::string net; |
1111 | | CV_PROP_RW int backend; |
1112 | | CV_PROP_RW int target; |
1113 | | CV_PROP_RW Scalar meanvalue; |
1114 | | CV_PROP_RW Scalar stdvalue; |
1115 | | CV_PROP_RW float tracking_score_threshold; |
1116 | | }; |
1117 | | |
1118 | | /** @brief Constructor |
1119 | | @param parameters vit tracker parameters TrackerVit::Params |
1120 | | */ |
1121 | | static CV_WRAP |
1122 | | Ptr<TrackerVit> create(const TrackerVit::Params& parameters = TrackerVit::Params()); |
1123 | | |
1124 | | #ifdef HAVE_OPENCV_DNN |
1125 | | /** @brief Constructor |
1126 | | * @param model pre-loaded DNN model |
1127 | | * @param meanvalue mean value for image preprocessing |
1128 | | * @param stdvalue std value for image preprocessing |
1129 | | * @param tracking_score_threshold threshold for tracking score |
1130 | | */ |
1131 | | static CV_WRAP |
1132 | | Ptr<TrackerVit> create(const dnn::Net& model, Scalar meanvalue = Scalar(0.485, 0.456, 0.406), |
1133 | | Scalar stdvalue = Scalar(0.229, 0.224, 0.225), float tracking_score_threshold = 0.20f); |
1134 | | #endif |
1135 | | |
1136 | | /** @brief Return tracking score |
1137 | | */ |
1138 | | CV_WRAP virtual float getTrackingScore() = 0; |
1139 | | |
1140 | | // void init(InputArray image, const Rect& boundingBox) CV_OVERRIDE; |
1141 | | // bool update(InputArray image, CV_OUT Rect& boundingBox) CV_OVERRIDE; |
1142 | | }; |
1143 | | |
1144 | | //! @} video_track |
1145 | | |
1146 | | } // cv |
1147 | | |
1148 | | #endif |