6.0 KiB
============================================================ TASK 01 OF 8 : OBJECT DETECTION USING PYTHON
TASK TITLE Object Detection Using Python
DESCRIPTION Implement and test the 01_detection.py script to detect objects in a live camera feed and draw a bounding box, class name and confidence score around each one.
PLATFORM NVIDIA Jetson Orin Nano, YOLO26 model, Python 3, OpenCV
============================================================ WHAT THIS SCRIPT DOES
- Opens the webcam / camera feed
- Loads the YOLO26n detection model and warms it up with a dummy image
- Runs object detection on every frame (80 COCO classes such as person, car, chair)
- Draws a green bounding box, class name and confidence on every object
- Shows live FPS and the number of objects on screen
============================================================ WHEN TO USE THIS
Use it when you only need to know WHAT is in the frame and WHERE (as a box). It does not give object IDs, pixel-exact shapes or body pose.
============================================================ HOW IT DIFFERS FROM THE OTHER SCRIPTS
02_tracking.py same detection, plus a persistent ID per object 03_segmentation.py exact pixel outline instead of a box 04_pose_estimation.py body joints / keypoints for people 05_classification.py one label for the whole frame, no boxes
============================================================ REQUIREMENTS AND SETUP
- Device: NVIDIA Jetson Orin Nano (JetPack installed, CUDA available)
- Camera: USB webcam (Logitech BRIO 100 or any UVC camera)
- Python 3 with these packages: pip3 install ultralytics opencv-python numpy Note: on Jetson, install the NVIDIA-built PyTorch and torchvision wheels for your JetPack version first, so that PyTorch uses the GPU. See the Ultralytics NVIDIA Jetson guide in the references below.
- Check that the camera is detected: ls /dev/video* v4l2-ctl --list-devices
- Optional - get the best speed from the board before running: sudo nvpmodel -m 0 sudo jetson_clocks
============================================================ COMMAND TO RUN
Open a terminal in the folder that contains the scripts and run:
python3 01_detection.py
Press Q in the video window to quit.
Run it again with the Jetson in max performance mode if FPS is low:
sudo nvpmodel -m 0 && sudo jetson_clocks && python3 01_detection.py
============================================================ SETTINGS YOU CAN CHANGE (top of 01_detection.py)
CAMERA_INDEX which camera to open (0 = default) FRAME_W/FRAME_H capture resolution (1280 x 720) CONF_THRESHOLD ignore detections below this confidence (0.45) IOU_THRESHOLD NMS threshold that removes duplicate boxes (0.45) MODEL_WEIGHTS model file (yolo26n.pt)
============================================================ EXPECTED OUTPUT
A live window titled 'YOLO - Detection' with green boxes, labels like 'person 0.87', and a yellow FPS / Objects counter in the top-left corner.
============================================================ VERIFY THE RESULT
Verify the script execution and validate the output:
- The camera window opens without errors.
- Hold a person / bottle / phone in front of the camera - a box with the right label appears.
- The FPS counter updates continuously.
- Pressing Q closes the window cleanly.
============================================================ TENSORRT BOOST (OPTIONAL)
For a big speed-up on Jetson, export the model once to a TensorRT engine and point MODEL_yolo26n.pt at the generated .engine file: yolo export model=yolo26n.pt format=engine half=True device=0 Then set MODEL_yolo26n.pt = 'yolo26n.engine' in the script and run it the same way as before.
============================================================ TROUBLESHOOTING
- Error: could not open camera Change CAMERA_INDEX at the top of the script (try 0, 1, 2). Run ls /dev/video* to see which index your camera uses. Close any other program that is using the camera.
- Window does not open / "cannot connect to display" Run the script on the Jetson desktop, or set the display first: export DISPLAY=:0
- Very low FPS Make sure PyTorch uses the GPU (python3 -c "import torch; print(torch.cuda.is_available())" should print True). Lower FRAME_W / FRAME_H, use the nano (n) model, and export the model to TensorRT (see section TENSORRT BOOST).
- Weights file download fails The first run downloads the weights from the internet. Connect the Jetson to a network once, or copy the .pt file next to the script.
============================================================ REFERENCE LINKS
Detection task docs: https://docs.ultralytics.com/tasks/detect/ COCO dataset (80 classes): https://docs.ultralytics.com/datasets/detect/coco/ Predict mode docs: https://docs.ultralytics.com/modes/predict/ YOLO26 model docs: https://docs.ultralytics.com/models/yolo26/ Ultralytics GitHub: https://github.com/ultralytics/ultralytics Jetson setup guide: https://docs.ultralytics.com/guides/nvidia-jetson/ TensorRT export guide: https://docs.ultralytics.com/integrations/tensorrt/ OpenCV documentation: https://docs.opencv.org/4.x/