Nodes/comfyui_cv/CV Track Window
ComfyUI Node

CV Track Window

One tracking step of cv2.meanShift / cv2.CamShift: slides the window uphill on a density map until it sits on the local mass peak. The density is typically 'CV Back Project' output (histogram tracking), but any single-channel likelihood map works (a threshold mask, a heatmap...). Chain one node per frame: this window output -> the next frame's window input; seed the first frame with a 'CV Scalar' literal like '(x, y, w, h)'. The raw cv2_meanShift wrapper cannot chain (its rect comes out as a text literal) - this node keeps the window as a wireable NPARRAY. Failure-tolerant: a window off the image, a degenerate size or a density with no mass under the result yields found=false and echoes the INPUT window unchanged (the track holds its last position instead of erroring) - branch on 'found' with if/else. Visualize: bbox -> the core 'Draw BBoxes' node; box_edges -> 'CV Draw Segments' (shows CamShift's rotated box).

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Track Window
  • density
  • window
  • window
  • bbox
  • box_edges
  • center
  • found
methodmeanShift (fixed-size window)
iterations10
epsilon1.0
min_density0
Categoryimage/CV/features

Inputs (6)

NameTypeDefaultDescription
densityNPARRAY,IMAGEDensity/likelihood map the window climbs on - usually an 'CV Back Project' map. Color input is converted to grayscale. 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.
windowNPARRAYSearch window as 4 numbers (x, y, w, h): a 'CV Scalar' literal for the first frame, the previous 'CV Track Window' window output afterwards.
methodCOMBOmeanShift (fixed-size window)meanShift keeps the window size fixed (steady, needs a roughly constant object size); CamShift also fits size + orientation (box_edges shows the rotated box) but can balloon on weak densities.
iterationsINT101–1000Maximum hill-climbing iterations per step; 10 is the classic tracking value.
epsilonFLOAT1.00–100Stop when the window center moves less than this many pixels between iterations.
min_densityFLOAT00–255Minimum AVERAGE density inside the result window for 'found' to be true. 0 accepts any non-zero mass; raise it (e.g. 32 on a 0-255 back-projection) so a few stray matching pixels do not count as a locked track.

Outputs (5)

NameTypeDescription
windowNPARRAYTracked window (x, y, w, h) as int32 - wire into the next frame's window input. Echoes the input window when found=false.
bboxBOUNDING_BOXThe same window as core BOUNDING_BOX data ({x, y, width, height}) - chain into the core 'Draw BBoxes' node.
box_edgesNPARRAYThe box outline as 4 segments (4x4 endpoint quadruples) for 'CV Draw Segments' - CamShift's actual rotated box, meanShift's window rectangle.
centerNPARRAYBox center as a 1x2 float array - collect centers to draw the trajectory with 'CV Draw Points' or 'CV Draw Segments'.
foundBOOLEAN