cv2.optflow.calcOpticalFlowSF (2/2)
The same SimpleFlow, now with all fifteen knobs
- from_
- to
- nparray
Same cv2 function as cv2.optflow.calcOpticalFlowSF (1/2), different overload. If the (1/2) node is "3 layers, block 2, max flow 4" and hope, this is the version where you can actually argue with the estimator: how aggressively it weights colour similarity, what counts as occluded, how much it smooths the field it just built.
You use one of the two. They're not stages.
What the extra knobs are
The first five inputs - from_, to, layers, averaging_block_size, max_flow - are identical to the (1/2) node and behave the same way (8-bit 3-channel frames of the same size, and 0 in those INT boxes is a value, not a default). Then the tail:
sigma_distandsigma_color- the falloff of the edge-aware weighting used when the sparse matches get interpolated into a dense field. Spatial distance vs colour difference. Highersigma_colorsurvives stronger edges; lower smooths across them.postprocess_window- the window the post-pass works over.sigma_dist_fixandsigma_color_fix- a second, fixed-parameter pass with the same two ideas.occ_thr- the occlusion threshold. Slightly above 0.5 is the folklore value; it decides which matched pixels get treated as occluded and therefore untrustworthy.upscale_averaging_radius,upscale_sigma_dist,upscale_sigma_color- the parameters for upsampling the coarse field at each pyramid level. This is where the visible smoothness comes from.speed_up_thr- an early-exit threshold for the internal iterative optimisation. Raise it to get your afternoon back, at the cost of exactly the accuracy you came here for.
All of these arrive at 0. The ? in the node description marks the parameters you can leave blank and get OpenCV's default; none of these are optional, so every one of them is a number you're sending to cv2. Zero is not neutral here - a zero colour sigma means the colour term is switched off, a zero occlusion threshold means nothing is ever occluded. Don't treat the defaults in the box as defaults. Copy the values from the SimpleFlow section of OpenCV's docs, or steal them from the sample, and only then start moving one at a time.
Output
One nparray, H x W x 2 float32 - per-pixel (dx, dy) in pixels. It's a data socket, not an image. To see it, CV Flow To Color (HSV direction wheel) or CV Draw Flow Grid (arrows); to use it, CV Flow Map into low-level cv2_remap, or any other NPARRAY consumer. To just look at numbers, Inspect CV Data and CV Array Shape are the debug pair.
Batch behaviour, and why it matters here
SimpleFlow is not in the pack's per-frame-batch list. Hand it a 10-frame IMAGE batch on each side and you get frame 0 of each, and one field - silently. For a clip you want per-pair flow, so make the pairs explicit with CV Index Batch (frame i and frame i+1), or accept that you're doing this frame by frame in a loop and nobody's judging you.
And because it's a two-input estimator, "the frames must be the same size" isn't a formality: resized or letterboxed second frames produce a field that looks plausible and is wrong.
It runs out of process, on purpose
optflow.calcOpticalFlowSF sits in the pack's unconditional-offload list, alongside calcOpticalFlowFarneback, fastNlMeansDenoising, pyrMeanShiftFiltering and friends. Each call spawns a worker subprocess, pickles the resolved arguments across, and polls for cancel - so the Cancel button actually works on a call that would otherwise block for minutes. Expect about a second of spawn overhead per call; the pack's authors concluded that's noise compared to what SimpleFlow already costs. On a 1080p pair, it is.
Practical fallout: downscale to something small (a quarter size is plenty for most motion analysis), and if you're tuning those fifteen parameters, iterate on one short pair, not on the clip.
Installing
ComfyUI Manager → search ComfyUI CV → Install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"
Python ≥ 3.12, recent ComfyUI (V3 node API), OpenCV 5.0.0.93 as the curated reference. No models, no weights, nothing to download.
The two failures you'll actually hit
The node is missing. optflow is a contrib module and the pack only builds wrappers for functions your installed cv2 exposes. A core-only build doesn't produce an error, it produces an absence. Install the contrib wheel and, if nodes have gone missing after some other package touched OpenCV, check with:
python ComfyUI/custom_nodes/comfyui_cv/tools/repair_opencv_contrib.py --check
python ComfyUI/custom_nodes/comfyui_cv/tools/repair_opencv_contrib.py --apply
Garbage field, no error. All-zero parameters produce a field that's technically a numpy array and practically noise. If your flow looks like static, look at the tail of the parameter list before you blame the estimator. Equally: if you're new to this, start with CV Optical Flow (Farneback) - one node, defaults that work, and it handles batches. Come back to SimpleFlow when Farneback is visibly losing your large motion.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| from_ | NPARRAY,IMAGE,MASK | - - - 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. | |
| to | NPARRAY,IMAGE,MASK | - - - 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. | |
| layers | INT | 0-2147483648–2147483647 | - - - |
| averaging_block_size | INT | 0-2147483648–2147483647 | - - - |
| max_flow | INT | 0-2147483648–2147483647 | - - - |
| sigma_dist | FLOAT | 0.0000-1e+38–1e+38 | - - - |
| sigma_color | FLOAT | 0.0000-1e+38–1e+38 | - - - |
| postprocess_window | INT | 0-2147483648–2147483647 | - - - |
| sigma_dist_fix | FLOAT | 0.0000-1e+38–1e+38 | - - - |
| sigma_color_fix | FLOAT | 0.0000-1e+38–1e+38 | - - - |
| occ_thr | FLOAT | 0.0000-1e+38–1e+38 | - - - |
| upscale_averaging_radius | INT | 0-2147483648–2147483647 | - - - |
| upscale_sigma_dist | FLOAT | 0.0000-1e+38–1e+38 | - - - |
| upscale_sigma_color | FLOAT | 0.0000-1e+38–1e+38 | - - - |
| speed_up_thr | FLOAT | 0.0000-1e+38–1e+38 | - - - |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |