How tekeaccesslab/ros2_color_detector_package works
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++)