# tekeaccesslab/ros2_color_detector_package architecture

> Architecture diagram of the GitHub repository tekeaccesslab/ros2_color_detector_package, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tekeaccesslab/ros2_color_detector_package
- Repository: https://github.com/tekeaccesslab/ros2_color_detector_package

## Overview

##### Project type and purpose
- Purpose: capture webcam frames (Python node), publish them on a ROS topic, subscribe in a C++ node, detect blue pixels, convert them to red, and display or republish the processed image.

##### File structure
- Top‐level “src” folder contains three ROS 2 packages:
– orange: a Python package (webcam_driver node).
– green: a C++ package (color_filter node).
– cpp_launch: a Python “launch” package (launch script).
- Each package has its own package.xml and build config (setup.py/CMakeLists.txt).
- There are build/, install/, and log/ trees—standard Colcon build outputs.
- Dependencies scattered in package.xml: image_transport, cv_bridge, OpenCV, ROS 2 rclpy/rclcpp.

##### README for additional insights
- It explains two runtime nodes:
– webcam_driver publishes /webcam/image_raw.
- The launch.py in cpp_launch starts both nodes under a single ROS 2 launch.

a. Main components
1. Hardware: Webcam (USB camera)
2. ROS 2 Middleware (DDS) acting as the pub/sub bus
3. Python node “webcam_driver” (orange package)
- Captures and encodes cv::Mat frames via OpenCV
- Uses cv_bridge + image_transport to publish sensor_msgs/Image on /webcam/image_raw
4. C++ node “color_filter” (green package)
- Subscribes to /webcam/image_raw
- Runs pixel‐wise blue‐to‐red transformation using OpenCV
- Optionally republishes processed frames or displays them
5. Launch orchestrator (cpp_launch)
- Starts and supervises both nodes under a single CLI command
6. External libraries/dependencies
- OpenCV, cv_bridge, image_transport, ROS 2 core libraries (rclpy, rclcpp)

b. Relationships and data flow
- Webcam → Python node (webcam_driver) → publishes → ROS 2 DDS
- ROS 2 DDS → C++ node (color_filter) → process → (optionally) publish or display
- Launch script → starts both nodes concurrently

c. Architectural patterns and design principles
- Pub/Sub decoupling between capture and processing
- Single‐responsibility nodes (capture vs. filter)
- Reuse of ROS 2 standard interfaces (sensor_msgs/Image, image_transport)
- Modular packages, each with its own language and build system (Python vs. C++)

d. Key technologies/frameworks
- ROS 2 Humble (DDS middleware)
- OpenCV for image handling
- cv_bridge for ROS-CV interoperability
- image_transport for efficient image topics
- rclpy (Python), rclcpp (C++)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Camera["Webcam Camera"]:::hardware

    subgraph "orange package"
        OR_pkg["package.xml"] 
        OR_setup_py["setup.py"]
        OR_setup_cfg["setup.cfg"]
        OR_node["webcam_driver.py"]
    end

    subgraph "green package"
        GR_pkg["package.xml"]
        GR_cmake["CMakeLists.txt"]
        GR_node["color_filter.cpp"]
    end

    subgraph "cpp_launch package"
        LP_pkg["package.xml"]
        LP_cmake["CMakeLists.txt"]
        LP_launch["launch.py"]
    end

    DDS["ROS 2 Middleware\n(DDS)"]:::middleware

    Camera --> OR_node
    OR_node -->|"/webcam/image_raw (sensor_msgs/Image)"| DDS
    DDS -->|"/webcam/image_raw (sensor_msgs/Image)"| GR_node

    LP_launch --> OR_node
    LP_launch --> GR_node

    click OR_pkg "https://github.com/tekeaccesslab/ros2_color_detector_package/blob/main/src/orange/package.xml"
    click OR_setup_py "https://github.com/tekeaccesslab/ros2_color_detector_package/blob/main/src/orange/setup.py"
    click OR_setup_cfg "https://github.com/tekeaccesslab/ros2_color_detector_package/blob/main/src/orange/setup.cfg"
    click OR_node "https://github.com/tekeaccesslab/ros2_color_detector_package/blob/main/src/orange/orange/webcam_driver.py"

    click GR_pkg "https://github.com/tekeaccesslab/ros2_color_detector_package/blob/main/src/green/package.xml"
    click GR_cmake "https://github.com/tekeaccesslab/ros2_color_detector_package/blob/main/src/green/CMakeLists.txt"
    click GR_node "https://github.com/tekeaccesslab/ros2_color_detector_package/blob/main/src/green/src/color_filter.cpp"

    click LP_pkg "https://github.com/tekeaccesslab/ros2_color_detector_package/blob/main/src/cpp_launch/package.xml"
    click LP_cmake "https://github.com/tekeaccesslab/ros2_color_detector_package/blob/main/src/cpp_launch/CMakeLists.txt"
    click LP_launch "https://github.com/tekeaccesslab/ros2_color_detector_package/blob/main/src/cpp_launch/launch/launch.py"

    classDef hardware fill:#DDDDDD,stroke:#333;
    classDef middleware fill:#ADD8E6,stroke:#333;
    classDef python fill:#FFA500,stroke:#333;
    classDef cpp fill:#98FB98,stroke:#333;
    classDef launch fill:#F5F5F5,stroke-dasharray:5 5,stroke:#333;

    class OR_pkg,OR_setup_py,OR_setup_cfg,OR_node python;
    class GR_pkg,GR_cmake,GR_node cpp;
    class LP_pkg,LP_cmake,LP_launch launch;
    class Camera hardware;
    class DDS middleware;
```
