calcOpticalFlowFarneback
import { calcOpticalFlowFarneback } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
example: samples/python/snippets/opt_flow.py An example to show optical flow in python Computes a dense optical flow using the Gunnar Farneback's algorithm.
Note: Some examples:
- An example using the optical flow algorithm described by Gunnar Farneback can be found at opencv_source_code/samples/cpp/fback.cpp
- (Python) An example using the optical flow algorithm described by Gunnar Farneback can be found at opencv_source_code/samples/python/opt_flow.py
calcOpticalFlowFarneback(prev: Mat, next: Mat, flow: Mat, pyr_scale: number, levels: number, winsize: number, iterations: number, poly_n: number, poly_sigma: number, flags: number): void;prevfirst 8-bit single-channel input image.
nextsecond input image of the same size and the same type as prev.
flowInput/output value, modified by the native operation. computed flow image that has the same size as prev and type CV_32FC2.
pyr_scaleparameter, specifying the image scale (<1) to build pyramids for each image; pyr_scale=0.5 means a classical pyramid, where each next layer is twice smaller than the previous one.
levelsnumber of pyramid layers including the initial image; levels=1 means that no extra layers are created and only the original images are used.
winsizeaveraging 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.
iterationsnumber of iterations the algorithm does at each pyramid level.
poly_nsize 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 poly_n =5 or 7.
poly_sigmastandard deviation of the Gaussian that is used to smooth derivatives used as a basis for the polynomial expansion; for poly_n=5, you can set poly_sigma=1.1, for poly_n=7, a good value would be poly_sigma=1.5.
flagsoperation flags that can be a combination of the following:
- OPTFLOW_USE_INITIAL_FLOW uses the input flow as an initial flow approximation.
- OPTFLOW_FARNEBACK_GAUSSIAN uses the Gaussian
\texttt{winsize}\times\texttt{winsize}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 prev pixel using the [Farneback2003] algorithm so that
\texttt{prev} (y,x) \sim \texttt{next} ( y + \texttt{flow} (y,x)[1], x + \texttt{flow} (y,x)[0])
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.