Computes a dense optical flow using the Gunnar Farneback’s algorithm.
Usage
farneback(
image1,
image2,
pyr_scale = 0.5,
levels = 3,
winsize = 43,
iterations = 3,
poly_n = 7,
poly_sigma = 1.5,
use_init = FALSE,
Gaussian = FALSE,
target = "new"
)
Arguments
- image1
A single-channel, 8U
Image
object.- image2
A single-channel, 8U
Image
object.- pyr_scale
Parameter, 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.
- 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.
- poly_n
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 poly_n = 5 or 7.
- poly_sigma
Standard 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.
- use_init
A logical indicating whether the content of
target
should be used as an initial flow approximation.- Gaussian
A logical indicating whether to use a Gaussian filter instead of a box filter for optical flow estimation; usually, this option gives a 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.- target
The location where the results should be stored. It can take 3 values:
Value
If target="new"
, the function returns an Image
object. If target
is an Image
object, the function
returns nothing and modifies that Image
object in place. The
Image
object will have two channels corresponding to the x and
y coordinates (respectively) of the optical vector at each location in the
image.
References
Farnebäck G. Two-Frame Motion Estimation Based on Polynomial Expansion. In: Bigun J, Gustavsson T, editors. Image Analysis. Springer Berlin Heidelberg; 2003. pp. 363–370. doi:10.1007/3-540-45103-X_50
Author
Simon Garnier, garnier@njit.edu
Examples
balloon <- video(system.file("sample_vid/Balloon.mp4", package = "Rvision"))
#> Error: Could not open the video.
balloon1 <- readFrame(balloon, 1)
#> Error in eval(expr, envir, enclos): object 'balloon' not found
changeColorSpace(balloon1, "GRAY", "self")
#> Error in eval(expr, envir, enclos): object 'balloon1' not found
balloon2 <- readFrame(balloon, 2)
#> Error in eval(expr, envir, enclos): object 'balloon' not found
changeColorSpace(balloon2, "GRAY", "self")
#> Error in eval(expr, envir, enclos): object 'balloon2' not found
of <- farneback(balloon1, balloon2)
#> Error in eval(expr, envir, enclos): object 'balloon1' not found