Skip to content

screamlab/ros2_yolo_integration

 
 

Repository files navigation

ros2_yolo_integration

yolo_pkg

Usage

  1. Run the provided activation script to start the container and prepare the environment
./yolo_activate.sh
  1. Do colcon build and source ./install/setup.bash
r
  1. Run yolo node
ros2 run yolo_pkg yolo_detection_node

Mode

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.
  • 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.

Function

  • 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).

class diagram

Logo

yolo_example_pkg

This is a ROS 2 project for integrating YOLO with ROS 2, providing functionality for real-time object detection and bounding box visualization.

Features

  • 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.

Usage

  1. Run the provided activation script to start the container and prepare the environment
./yolo_activate.sh
  1. Do colcon build and source ./install/setup.bash
r
  1. Run yolo node
ros2 run yolo_example_pkg yolo_node

How to put your yolo model

To use the YOLO model in this package, follow these steps:

  1. 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.pt
    

    You can update the model used in the following files inside yolo_pkg:

    • yolo_segmentation_model.py
    • yolo_detect_model.py
  2. 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"
    )
    

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 94.7%
  • Dockerfile 2.7%
  • Shell 2.6%