6.9 KiB
YOLO26: 8 Computer Vision Tasks on Video (Jetson Orin Nano)
Task Title
Run 8 YOLO26 computer vision tasks on a single input video using Python.
Description
One script runs the YOLO26 model family on one video file (ai_video.mp4) and saves every result into a results/ folder. Each task loads its own YOLO26 nano model, processes the video frame by frame (streaming, so memory stays low on the Jetson) and writes an annotated output video or files.
Tasks in the script:
- Detection: boxes, class names and confidence on every frame, saved as a video.
- Tracking: real tracking, object IDs persist across frames, saved as a video.
- Segmentation: pixel-level masks on every frame, saved as a video.
- Pose estimation: skipped by default (code kept but commented out).
- Classification: top-1 label per frame overlaid on the video, plus a text log.
- ROI extraction: crops each detected box out of sampled frames and saves each crop as an image.
- Depth estimation: native YOLO26 depth model, saved as a colorized depth video plus raw depth arrays.
- OBB (oriented bounding boxes): skipped by default (code kept but commented out).
Hardware and Software
- Device: NVIDIA Jetson Orin Nano (JetPack with CUDA and TensorRT)
- Language: Python 3
- Libraries: ultralytics, opencv-python, numpy
- Input:
ai_video.mp4in the same folder as the script
Installation
pip install -U ultralytics
On Jetson, install the JetPack-matched PyTorch and torchvision builds first (see the Jetson guide in the references). Model weights download automatically on first run, so the first run needs internet.
Folder Layout
your_folder/
yolo26_8_tasks_video.py (rename to match your script file name)
ai_video.mp4
results/ (created automatically)
Command to Run
python3 yolo26_8_tasks_video.py
To use a different video, change VIDEO_PATH at the top of the script.
Models Used
- Task 1 and 2 and 6:
yolo26n.pt(detection, COCO 80 classes) - Task 3:
yolo26n-seg.pt(instance segmentation) - Task 4 (optional):
yolo26n-pose.pt(17 human keypoints) - Task 5:
yolo26n-cls.pt(ImageNet 1000 classes) - Task 7:
yolo26n-depth.pt(per-pixel metric depth in meters, run at imgsz=768) - Task 8 (optional):
yolo26n-obb.pt(DOTA aerial classes)
Settings You Can Change
VIDEO_PATH = "ai_video.mp4": input videoOUT_DIR = "results": folder for all outputsROI_FRAME_STRIDE = 15: save ROI crops every 15th frameDEPTH_NPY_STRIDE = 30: save a raw depth.npyfile every 30th frameimgsz=768in the depth call : depth model input size; lower it if the Jetson runs out of memory
How It Works
- The script checks that the video exists and reads its FPS, width, height and frame count.
- Each task runs inside its own
try/except, so if one task fails the others still run and the failure is printed as[n - Task] FAILED. - Detection, tracking, segmentation and classification call the model with
stream=True, read each result and writeresult.plot()to an output video. - Tracking uses
track(..., persist=True)so IDs stay the same across frames. - ROI extraction reuses the detection results from Task 1 and crops boxes only on sampled frames, because a full video would create thousands of files.
- Depth estimation reads
result.depth.data(a float32 map in meters), normalizes it, applies the MAGMA color map and writes a colorized video. It prints the minimum and maximum depth across the clip.
Output Files (inside results/)
1_detection.mp4: detection video2_tracking.mp4: tracking video with persistent IDs3_segmentation.mp4: segmentation video5_classification.mp4: per-frame classification video5_classification_log.txt: one line per frame with the top-1 label and confidence6_roi_crops/: cropped objects, named likeframe15_roi0_person.png7_depth.mp4: colorized depth video7_depth_raw/: raw depth arrays likeframe30.npy(meters)
Verify the Output
- The console prints the video size, FPS and frame count at the start.
- Each finished task prints
Saved:with its path. results/contains the videos, the log, the crops folder and the depth folder.- In
2_tracking.mp4the same object keeps the same ID while it moves. - In
3_segmentation.mp4the colored masks follow object shapes. - In
7_depth.mp4nearer objects and farther objects have clearly different colors. - The final line prints
Done. Check the 'results' folder for all saved outputs.
Notes and Limitations
- Pose (task 4): the pose model finds human keypoints. If the video has no person, every frame returns nothing. Uncomment the block and use footage with people.
- OBB (task 8): the OBB model is trained on aerial and satellite classes (planes, ships, vehicles, storage tanks). On everyday scenes it returns nothing. Uncomment the block and use aerial footage.
- Classification (task 5): classification expects one main subject per frame. With many objects in view the top-1 label is only a rough per-frame guess, not a scene description.
- ROI (task 6): this is not a separate YOLO model. It crops the detected boxes from the original frame.
Optional: Faster Inference with TensorRT
Export a model once and use the engine file in the script:
yolo export model=yolo26n.pt format=engine half=True
Then replace YOLO("yolo26n.pt") with YOLO("yolo26n.engine").
Troubleshooting
Could not open 'ai_video.mp4': put the video in the same folder as the script or fixVIDEO_PATH.- Output video is empty or cannot be played: install a player that supports
mp4v, or change the codec inopen_writer. - Out of memory on Jetson: close other apps, lower
imgszfor depth, or run one task at a time. - Low speed: run
sudo nvpmodel -m 0andsudo jetson_clocks, or export to TensorRT. - Weights fail to download: connect to the internet for the first run, or copy the
.ptfiles next to the script.
References
- Ultralytics YOLO26 models
- Object detection task
- Object tracking mode
- Instance segmentation task
- Pose estimation task
- Image classification task
- Oriented bounding boxes (OBB) task
- Depth estimation task
- Predict mode (streaming inference)
- Ultralytics on NVIDIA Jetson guide
- TensorRT export
- Ultralytics GitHub
- Ultralytics on PyPI
- OpenCV VideoWriter docs