Update README.md

This commit is contained in:
2026-11-04 05:31:02 +00:00
parent 460877386e
commit a4c8af49f3
+86 -109
View File
@@ -1,130 +1,107 @@
============================================================
TASK 01 OF 8 : OBJECT DETECTION USING PYTHON
============================================================
# Task 01: Object Detection Using Python
## Task Title
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.
## Description
PLATFORM
NVIDIA Jetson Orin Nano, YOLO26 model, Python 3, OpenCV
Implement and test the `01_detection.py` script on the Jetson Orin Nano. Opens a camera feed, runs YOLO26n object detection on every frame and draws a bounding box, class name and confidence for each object (80 COCO classes). Live FPS and object count are shown on screen.
============================================================
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
============================================================
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.
Use this when you only need to know WHAT is in the frame and WHERE (as a box). It does not track objects across frames, give pixel-exact shapes, or find body joints.
============================================================
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
## Hardware and Software
============================================================
REQUIREMENTS AND SETUP
============================================================
1. Device: NVIDIA Jetson Orin Nano (JetPack installed, CUDA available)
2. Camera: USB webcam (Logitech BRIO 100 or any UVC camera)
3. 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.
4. Check that the camera is detected:
ls /dev/video*
v4l2-ctl --list-devices
5. Optional - get the best speed from the board before running:
sudo nvpmodel -m 0
sudo jetson_clocks
- 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
============================================================
COMMAND TO RUN
============================================================
Open a terminal in the folder that contains the scripts and run:
## 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 01_detection.py
```
Press Q in the video window to quit.
Check the camera is visible before running:
Run it again with the Jetson in max performance mode if FPS is low:
```
ls /dev/video*
```
sudo nvpmodel -m 0 && sudo jetson_clocks && python3 01_detection.py
## How It Works
============================================================
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)
1. Load the YOLO26n model once and run a warm-up pass on a dummy image so the first real frame is not slow.
2. Open the camera with OpenCV and set the resolution (1280x720).
3. For every frame call the model with the confidence and IoU thresholds.
4. Read boxes, class ids and confidences from the result and draw them with OpenCV.
5. Compute and overlay FPS and the number of detected objects. Press Q to quit.
============================================================
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.
## Settings You Can Change
============================================================
VERIFY THE RESULT
============================================================
Verify the script execution and validate the output:
1. The camera window opens without errors.
2. Hold a person / bottle / phone in front of the camera - a box with the right label appears.
3. The FPS counter updates continuously.
4. Pressing Q closes the window cleanly.
Edit these values at the top of the script:
============================================================
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.
- CAMERA_INDEX = 0 : which camera to open (0 = default)
- FRAME_W / FRAME_H = 1280 / 720 : capture resolution
- CONF_THRESHOLD = 0.45 : ignore detections below this confidence
- IOU_THRESHOLD = 0.45 : Non-Max-Suppression threshold that removes duplicate boxes
- MODEL_WEIGHTS = yolo26n.pt : nano model, smallest and fastest, good for Jetson
============================================================
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.
## Controls
============================================================
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/
- Press `Q` to quit the live window
============================================================
END OF README - 01_detection.py
============================================================
## Verify the Output
Run `python3 01_detection.py` and confirm:
- [ ] A live window titled 'YOLO - Detection' opens.
- [ ] Green boxes with labels like 'person 0.87' appear around objects.
- [ ] FPS and Objects counters show at the top-left.
- [ ] Pressing Q closes the window cleanly.
## 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
02_tracking adds persistent IDs, 03_segmentation gives pixel masks, 04_pose_estimation finds keypoints, 05_classification labels the whole frame.
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
- [Ultralytics YOLO26 model page](https://docs.ultralytics.com/models/yolo26/)
- [Object detection task docs](https://docs.ultralytics.com/tasks/detect/)
- [Predict mode docs](https://docs.ultralytics.com/modes/predict/)
- [COCO dataset (80 classes)](https://docs.ultralytics.com/datasets/detect/coco/)
- [Ultralytics on NVIDIA Jetson guide](https://docs.ultralytics.com/guides/nvidia-jetson/)
- [TensorRT export](https://docs.ultralytics.com/integrations/tensorrt/)
- [Ultralytics GitHub](https://github.com/ultralytics/ultralytics)
- [JetPack SDK](https://developer.nvidia.com/embedded/jetpack)