calcOpticalFlowFarneback
Computes a dense optical flow using the Gunnar Farneback’s algorithm.
- C++: void calcOpticalFlowFarneback(InputArray prevImg, InputArray nextImg, InputOutputArray flow, double pyrScale, int levels, int winsize, intiterations, int polyN, double polySigma, int flags)
- C: void cvCalcOpticalFlowFarneback(const CvArr* prevImg, const CvArr* nextImg, CvArr* flow, double pyrScale, int levels, int winsize, int iterations, int polyN, double polySigma, int flags)
- Python: cv2.calcOpticalFlowFarneback(prevImg, nextImg, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags[, flow]) → flow
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Parameters .prevImg – First 8-bit single-channel input image. .nextImg – Second input image of the same size and the same type as prevImg . .flow – Computed flow image that has the same size as prevImg and type CV_32FC2 . .pyrScale – Parameter specifying the image scale (<1) to build pyramids for each image. pyrScale=0.5 means a classical pyramid, where each next layer is twice smaller than the previous one. .levels – Number of pyramid layers including the initial image. levels=1 means that no extra layers are created and only the original images are used. .winsize – Averaging window size. Larger values increase the algorithm robustness to image noise and give more chances for fast motion detection, but yield more blurred motion field. .iterations – Number of iterations the algorithm does at each pyramid level. .polyN – Size of the pixel neighborhood used to find polynomial expansion in each pixel. Larger values mean that the image will be approximated with smoother surfaces, yielding more robust algorithm and more blurred motion field. Typically, polyN =5 or 7. .polySigma – Standard deviation of the Gaussian that is used to smooth derivatives used as a basis for the polynomial expansion. For polyN=5, you can set polySigma=1.1 . For polyN=7 , a good value would be polySigma=1.5 .flags –Operation flags that can be a combination of the following: OPTFLOW_USE_INITIAL_FLOW Use the input flow as an initial flow approximation. OPTFLOW_FARNEBACK_GAUSSIAN Use the Gaussian filter instead of a box filter of the same size for optical flow estimation. Usually, this option gives z more accurate flow than with a box filter, at the cost of lower speed;Normally, winsize for a Gaussian window should be set to a larger value to achieve the same level of robustness. |
The function finds an optical flow for each prevImg pixel using the [Farneback2003] alorithm so that
calcOpticalFlowPyrLK
Computes sparse optical flow using multi-scale Lucas-Kanade algorithm
C++: CV_EXPORTS_W void calcOpticalFlowPyrLK( InputArray prevImg, InputArray nextImg, InputArray prevPts, CV_OUT InputOutputArray nextPts, OutputArray status, OutputArray err, Size winSize=Size(21,21), int maxLevel=3, TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), int flags=0, double minEigThreshold=1e-4);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
Parameters prevImg – First 8-bit single-channel or 3-channel input image. nextImg – Second input image of the same size and the same type as prevImg . prevPts – Vector of 2D points for which the flow needs to be found. The point coordinates must be single-precision floating-point numbers. nextPts – Output vector of 2D points (with single-precision floating-point coordinates) containing the calculated new positions of input features in the second image. When OPTFLOW_USE_INITIAL_FLOW flag is passed, the vector must have the same size as in the input. status – Output status vector. Each element of the vector is set to 1 if the flow for the corresponding features has been found. Otherwise, it is set to 0. err – Output vector that contains the difference between patches around the original and moved points. winSize – Size of the search window at each pyramid level. maxLevel – 0-based maximal pyramid level number. If set to 0, pyramids are not used (single level). If set to 1, two levels are used, and so on. criteria – Parameter specifying the termination criteria of the iterative search algorithm (after the specified maximum number of iterations criteria.maxCount or when the search window moves by less than criteria.epsilon . derivLambda – Not used. flags – Operation flags: – OPTFLOW_USE_INITIAL_FLOW Use initial estimations stored in nextPts . If the flag is not set, then prevPts is copied to nextPts and is considered as the initial estimate. |