Nodes/comfyui_cv/cv2.calcOpticalFlowFarneback
ComfyUI Node

cv2.calcOpticalFlowFarneback

Raw wrapper of cv2.calcOpticalFlowFarneback(prev, next, flow, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags). Parameters marked '?' are optional; blank means OpenCV default. See the OpenCV documentation for details.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
cv2.calcOpticalFlowFarneback
  • prev
  • next
  • flow
  • nparray
pyr_scale0.0000
levels0
winsize0
iterations0
poly_n0
poly_sigma0.0000
flagsnone (0)
Categoryimage/CV/low-level/cv2 C

Inputs (10)

NameTypeDefaultDescription
prevNPARRAY,IMAGE,MASKfirst 8-bit single-channel input image. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
nextNPARRAY,IMAGE,MASKsecond input image of the same size and the same type as prev. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
flowNPARRAY,IMAGE,MASKcomputed flow image that has the same size as prev and type CV_32FC2. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
pyr_scaleFLOAT0.0000-1e+38–1e+38parameter, 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.
levelsINT0-2147483648–2147483647number of pyramid layers including the initial image; levels=1 means that no extra layers are created and only the original images are used.
winsizeINT0-2147483648–2147483647averaging 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.
iterationsINT0-2147483648–2147483647number of iterations the algorithm does at each pyramid level.
poly_nINT0-2147483648–2147483647size 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_sigmaFLOAT0.0000-1e+38–1e+38standard 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.
flagsSTRINGnone (0)operation 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 algorithm so that $$\texttt{prev} (y,x) \sim \texttt{next} ( y + \texttt{flow} (y,x)[1], x + \texttt{flow} (y,x)[0])$$ cv2.calcOpticalFlowFarneback flags: one of none (0) plus any of OPTFLOW_USE_INITIAL_FLOW, OPTFLOW_FARNEBACK_GAUSSIAN, pipe-joined (e.g. "none (0) | OPTFLOW_USE_INITIAL_FLOW"). In the UI this renders as a dropdown with one toggle per flag.

Outputs (1)

NameTypeDescription
nparrayNPARRAY