Nodes/ComfyUI-YoloTrack/YOLO Tracking & Crop
ComfyUI Node

YOLO Tracking & Crop

Follow and Crop a Moving Subject in Video, Right Inside ComfyUI

By tppp2806·Created 9 months ago·Updated 9 months ago· 0
YOLO Tracking & Crop
  • image
  • cropped_image
  • mask
  • preview_with_marks
model_name
select_criteria
select_count1
confidence_threshold0.50
nms_threshold0.40
crop_ratio
crop_scale1.000
offset_x0.00
offset_y0.00
stabilization_method
stabilization_strength0.70
enable_predictiontrue
mask_type
limit_to_boundstrue
class_ids

YOLO Tracking & Crop (class YOLOTrackingNode) is the headliner of the tiny ComfyUI-YoloTrack pack. It does one thing nobody else in the graph does for free: detect an object, keep following it frame after frame, and crop it out of a video sequence at a fixed aspect ratio. If you've ever wanted a "track the person and keep them centered" node, this is it.

The obvious use is a detect-crop-resample loop - the same machinery Impact Pack's FaceDetailer made famous, but here you're pulling a moving subject out of frames to feed a detail pass or an upscaler. It's also the only convenient way to reframe in-graph: feed it a video batch and get a stable 9:16 crop that stays centered even as the subject wanders.

How it works

Read the source and the story is clear: this is re-detection plus selection, not a persistent-ID tracker. Every frame runs YOLO inference (with confidence_threshold and nms_threshold passed straight to Ultralytics), every detection gets sorted by your select_criteria, and the top select_count boxes win. That's where "tracking" actually comes from - pick Nearest to History and it keeps grabbing the object closest to where previous selections were, which makes it stick to one subject.

Two things keep the crop sane across frames: a BBoxStabilizer smooths each box (stabilization_method: EMA, Weighted Average, Kalman, or Hybrid, dialed by stabilization_strength), and enable_prediction extrapolates the box from velocity or Kalman state when the target briefly vanishes instead of dropping it. The crop is then centered on the primary (first selected) box, sized by crop_ratio and crop_scale, nudged by offset_x/offset_y, and clamped to the frame edges by limit_to_bounds.

One subtlety: the crop size locks on the first frame and stays fixed for the whole sequence. If the subject grows, set crop_scale for its biggest size or the crop will drift relative to it.

The inputs that matter

Most fields you can leave alone, but these are the ones you'll actually touch:

  • select_criteria - Nearest to History for following one object; Area Max, Confidence Max, or Center Nearest when there's an obvious target.
  • stabilization_method + stabilization_strength - start with EMA at 0.7; bump to 0.85 for slow targets, drop to ~0.5 for fast ones.
  • crop_ratio and crop_scale - the output aspect ratio and how much breathing room around the subject. offset_x/offset_y shift the crop center, but note they're in units of crop width/height, so ±2 is a huge nudge.
  • mask_type - Box fills the bounding box; Segmentation only produces real segment polygons if your model is a segmentation build (e.g. yolov8n-seg.pt). Stock yolov8n.pt has no masks, so it silently falls back to box fill.
  • class_ids (optional) - comma-separated COCO ids, e.g. 0 for person, 0,2 for person + car. Blank means everything.

Outputs: cropped_image, mask, and preview_with_marks (boxes + crop frame drawn on the original). Wire cropped_image into an upscaler or detail node; the mask is there if you want to composite the refined crop back.

Installing it

ComfyUI Manager: search YoloTrack and install. Or manually:

cd ComfyUI/custom_nodes/
git clone https://github.com/tppp2806/ComfyUI-YoloTrack
cd ComfyUI-YoloTrack
pip install -r requirements.txt

Then restart ComfyUI. Two things to know about models: drop .pt files in ComfyUI/models/yolo/, and if that folder is empty the dropdown falls back to the stock five (yolov8n through yolov8x) - the code then hands the name straight to Ultralytics, which auto-downloads it on first run. So the README's "auto-download" promise is real, not marketing. For speed use n/s; for accuracy l/x.

Gotchas and troubleshooting

  • The README's manual-install snippet is broken. It literally says git clone https://github.com/your-username/comfyui-YoloTrack.git. Use the real URL above.
  • Subject keeps getting lost - lower confidence_threshold, switch criteria to Nearest to History, and check class_ids isn't filtering it out.
  • Crop jitters between frames - that's what the stabilizers exist for; EMA at 0.7–0.85 with limit_to_bounds on is the boring, working setup. If it keeps re-centering on the wrong object, weak detections are winning the sort; raise the confidence threshold.
  • Crop edges cut the subject - raise crop_scale a touch. Turn off limit_to_bounds and the crop will track past the frame edge, but you'll get black padding.
  • Heavy dependency - the pack pulls in Ultralytics, which is AGPL-licensed and carried a real cryptominer supply-chain compromise in December 2024. Fine for local tinkering; think twice before baking it into a distributed workflow.

The docs are mostly Chinese, but the node fields speak for themselves. Niche pack, no community footprint to speak of - if it does what you need, it does it well.

CategoryYOLO

Inputs (16)

NameTypeDefaultDescription
imageIMAGE
model_nameCOMBO5 options: yolov8n.pt, yolov8s.pt, yolov8m.pt, yolov8l.pt, yolov8x.pt
select_criteriaCOMBO11 options: Area Max, Area Min, Confidence Max, Confidence Min, Center Top, Center Bottom, +5
select_countINT11–100
confidence_thresholdFLOAT0.500–1
nms_thresholdFLOAT0.400–1
crop_ratioCOMBO8 options: Original, 1:1, 16:9, 9:16, 4:3, 3:4, +2
crop_scaleFLOAT1.0000.001–10000
offset_xFLOAT0.00-2–2
offset_yFLOAT0.00-2–2
stabilization_methodCOMBO5 options: None, EMA, Weighted Average, Kalman, Hybrid
stabilization_strengthFLOAT0.700–0.99
enable_predictionBOOLEANtrue
mask_typeCOMBO2 options: Box, Segmentation
limit_to_boundsBOOLEANtrue
class_idsoptSTRING

Outputs (3)

NameTypeDescription
cropped_imageIMAGE
maskMASK
preview_with_marksIMAGE