108 lines
4.1 KiB
Markdown
108 lines
4.1 KiB
Markdown
# Task 01: Object Detection Using Python
|
|
|
|
## Task Title
|
|
|
|
Object Detection Using Python
|
|
|
|
## Description
|
|
|
|
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.
|
|
|
|
## When to Use
|
|
|
|
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.
|
|
|
|
## 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 01_detection.py
|
|
```
|
|
|
|
Check the camera is visible before running:
|
|
|
|
```
|
|
ls /dev/video*
|
|
```
|
|
|
|
## How It Works
|
|
|
|
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.
|
|
|
|
## Settings You Can Change
|
|
|
|
Edit these values at the top of the script:
|
|
|
|
- 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
|
|
|
|
## Controls
|
|
|
|
- Press `Q` to quit the live window
|
|
|
|
## 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)
|