- Run the provided activation script to start the container and prepare the environment
./yolo_activate.sh
- Do colcon build and source ./install/setup.bash
r
- Run yolo node
ros2 run yolo_pkg yolo_detection_node
The YOLO node can operate in different modes depending on your use case:
- Mode 1: Draw bounding boxes without screenshot
- Displays YOLO-detected bounding boxes on the output topic
/yolo/detection/compressed.
- Displays YOLO-detected bounding boxes on the output topic
- Mode 2: Draw bounding boxes with screenshot
- Captures a screenshot of each detected object and saves it.
- Mode 3: 5 fps screenshot.
- Takes a screenshot from the camera feed at a rate of 5 frames per second.
- Mode 4: segmentation
- Enables segmentation mode, displaying segmentation masks on the output topic
/yolo/detection/compressed.
- Enables segmentation mode, displaying segmentation masks on the output topic
- draw_bounding_boxes
draw_crosshair(bool) :- If set to True, the function will draw a crosshair at the center of the image.
screenshot(bool) :- If True, the function will capture a screenshot of the image after drawing the bounding boxes.
segmentation_status(bool) :- Controls whether the segmentation overlay is displayed on the output image.
bounding_status(bool) :- Controls whether bounding boxes are displayed on the output image.
- save_fps_screenshot
- Captures screenshots at a fixed rate of 5 frames per second (FPS).
This is a ROS 2 project for integrating YOLO with ROS 2, providing functionality for real-time object detection and bounding box visualization.
- Receive compressed images from the /yolo/detection/compressed topic.
- Process images to convert them into OpenCV format.
- Draw bounding boxes around detected objects on the images.
- Publish processed images back to the /yolo/detection/compressed topic, which includes the drawn bounding boxes.
- Run the provided activation script to start the container and prepare the environment
./yolo_activate.sh
- Do colcon build and source ./install/setup.bash
r
- Run yolo node
ros2 run yolo_example_pkg yolo_node
To use the YOLO model in this package, follow these steps:
-
Place the Model File
Download or obtain the YOLO .pt file (e.g., yolov8n.pt) and place it inside the models directory within the pkg folder:
<your_ros2_workspace>/ ├── src/ │ ├── yolo_example_pkg/ │ │ ├── models/ │ │ │ ├── yolov8n.pt ├── yolov8n-seg.ptYou can update the model used in the following files inside
yolo_pkg:yolo_segmentation_model.pyyolo_detect_model.py
-
Model Path Configuration
The script dynamically loads the model from the package's shared directory using the following code:
import os from ament_index_python.packages import get_package_share_directory model_path = os.path.join( get_package_share_directory("yolo_example_pkg"), "models", "yolov8n.pt" )
