Skip to content

shivanikhandelwal2001/Real-Time-Object-Tracking-ROS2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repository contains ros2 packages.

Object Tracking in ROS2

This project implements real-time object detection and tracking using ROS2 (Humble). The system captures images from a live camera or video, processes them through a YOLO V8 model, and tracks objects using a Centroid Tracking Algorithm.


Nodes & Topics

This project consists of the following ROS2 nodes:

Image Publisher (image_publisher)

  • Publishes: /camera/image_raw
  • Streams images from a live camera or video file.

Image Subscriber (image_subscriber)

  • Subscribes: /camera/image_raw
  • Publishes: /object_detection
  • Runs YOLOv8 to detect objects and outputs bounding boxes.

Object Tracking (object_tracking)

  • Subscribes: /object_detection
  • Publishes: /object_tracking
  • Tracks objects across frames using Centroid Tracking.

Visualization (visualization)

  • Subscribes: /camera/image_raw, /object_detection, /object_tracking
  • Publishes: /visualization/image
  • Overlays detections and tracking results on images.

Project Structure

Real-Time-Object-Tracking-ROS2/src/
│── object_tracking_viz/
│   ├── config/                         # YAML configuration files
│   │   ├── params.yaml                 # ROS2 parameters (camera, video file, tracking settings)
│   ├── include/object_tracking_viz/    # Cpp header files
│   │   ├── header.cpp         
│   ├── launch/                         # ROS2 launch files
│   │   ├── app.launch.py               # Launch all nodes
│   ├── media/                          # Sample video files for testing
│   │   ├── test1.mp4
│   │   ├── test2.mp4
│   │   ├── test3.mp4
│   ├── object_tracking_viz/            # Python packages
│   │   ├── __init__.py
│   ├── scripts/                        # Python scripts
│   │   ├── image_subscriber.py         # Subscribes images and detect objects using YOLOv8
│   │   ├── object_visualization.py     # Overlays tracking & detection results
│   ├── src/                            # C++ source files
│   │   ├── image_publisher.cpp         # Publishes images from camera or video
│   │   ├── object_tracking.cpp         # Tracks objects using Centroid Tracking
│   ├── CMakeLists.txt                  # ROS2 build configuration
│   ├── package.xml                     # Package dependencies
│── .gitignore
│── README.md                           # Project documentation

Installation

Clone this repository into your ROS2 workspace.

Install the ROS2 Hunble distribution:

https://docs.ros.org/en/humble/Installation.html

Dependencies

This project requires ROS2 Humble, along with additional system and Python dependencies.

System Dependencies

Install the required system packages:

sudo apt update && sudo apt install -y \
    python3-opencv \
    ros-humble-cv-bridge \
    ros-humble-image-transport \
    ros-humble-rclcpp \
    ros-humble-std-msgs \
    ros-humble-ament-index-cpp \
    libeigen3-dev

Python Dependencies

Install the required Python packages:

pip install opencv-python numpy ultralytics nlohmann-json

Build the Package

cd ~/Real-Time-Object-Tracking-ROS2
colcon build --packages-select object_tracking_viz
source install/setup.bash

Configuration (params.yaml)

Modify config/params.yaml to adjust the camera usage, video file name, and tracking settings

Running the Nodes

Use the launch file to start all ROS2 nodes:

ros2 launch object_tracking_viz app.launch.py

OR, manually run each node:

ros2 run object_tracking_viz image_publisher
ros2 run object_tracking_viz image_subscriber
ros2 run object_tracking_viz object_tracking
ros2 run object_tracking_viz object_visualization

RQT Graph

Below is the rqt_graph showing the ROS2 nodes and their connections.

ROS 2 Node Graph


Demo

Demo Video


Resources & References

Here are some helpful resources related to using WSL2, USB support in WSL2, Gazebo Simulation, and OpenCV VideoIO:

ROS2:

WSL2 & USB Camera in WSL2:

Additional Tutorials:

Gazebo Simulation:


Contributing

Contributions are welcome! Please fork the repository and create a pull request.

👩‍💻 Author

Developed by Shivani Khandelwal.

Connect with me here - Profile

For questions or improvements, feel free to reach out at shivanikhandelwal487@gmail.com.


About

Ros2 packages and projects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors