Files
Project_documents/02_tracking_README.md
T
2026-11-23 11:42:41 +05:30

3.8 KiB

Task 02: Object Tracking Using Python

Task Title

Object Tracking Using Python

Description

Implement and test the 02_tracking.py script on the Jetson Orin Nano. Runs YOLO26n detection and then tracks each object across frames, giving every object a persistent ID shown next to its box. Uses the Ultralytics tracking mode (ByteTrack by default).

When to Use

Use this when you need to follow the same object over time, for example counting unique people or vehicles, or measuring how long something stays in view.

Hardware and Software

  • Device: NVIDIA Jetson Orin Nano (JetPack with CUDA and TensorRT)
  • Camera: USB webcam (for example Logitech BRIO 100) at CAMERA_INDEX 0
  • Language: Python 3
  • Model: YOLO26 (Ultralytics), weights yolo26n.pt
  • Libraries: ultralytics, opencv-python, numpy

Installation

pip install ultralytics opencv-python

On Jetson, install the JetPack-matched PyTorch and torchvision builds first (see the Ultralytics Jetson guide in the references). Model weights download automatically on first run if the machine is online.

Command to Run

python3 02_tracking.py

Check the camera is visible before running:

ls /dev/video*

How It Works

  1. Load the YOLO26n model.
  2. Open the camera feed.
  3. Call the model's track function on each frame with persist=True so IDs carry over between frames.
  4. Read boxes, class ids and track IDs from the result and draw them.
  5. Show FPS and the number of tracked objects. Press Q to quit.

Settings You Can Change

Edit these values at the top of the script:

  • CAMERA_INDEX : which camera to open
  • FRAME_W / FRAME_H : capture resolution
  • CONF_THRESHOLD / IOU_THRESHOLD : detection thresholds
  • TRACKER : tracker config, bytetrack.yaml (fast) or botsort.yaml (more robust)
  • MODEL_WEIGHTS = yolo26n.pt

Controls

  • Press Q to quit the live window

Verify the Output

Run python3 02_tracking.py and confirm:

  • A live tracking window opens.
  • Each object has a box with a class name and an ID such as 'id:3 person'.
  • The ID stays the same while the object moves around the frame.
  • A new object gets a new ID; Q closes the window.

Optional: Faster Inference with TensorRT

For higher FPS on the Orin Nano, export the model to a TensorRT engine once and point MODEL_WEIGHTS to the engine file:

yolo export model=yolo26n.pt format=engine half=True

Then set MODEL_WEIGHTS = 'yolo26n.engine' in the script.

Troubleshooting

  • Camera not opening: check ls /dev/video*, try CAMERA_INDEX 1, and make sure no other app is using the camera.
  • Window does not show over SSH: run on the Jetson desktop, or use X11 forwarding.
  • Low FPS: use the nano model, lower FRAME_W / FRAME_H, run sudo nvpmodel -m 0 and sudo jetson_clocks, or export to TensorRT.
  • Weights not found: connect to the internet for the first run or copy the .pt file next to the script.
  • Out of memory: close other apps and reduce the input size.

How This Differs From the Other Tasks

Same as 01_detection but with persistent IDs across frames.

Files in this folder: 01_detection, 02_tracking, 03_segmentation, 04_pose_estimation, 05_classification, 06_roi_detection, 07_obb_detection, 08_depth_estimation.

References