image_common

repository·rolling·Indexed 41 days ago

https://github.com/ros-perception/image_common

A collection of ROS 2 packages providing core infrastructure for image handling and camera calibration. It includes image_transport for efficient raw and compressed image transport, camera_info_manager for managing calibration data, camera_calibration_parsers for YAML and INI format support, and the polled_camera protocol for requesting images from polling camera drivers.

Tokens
12.8K
Snippets
32
Records
58
Agent score
98%

What's inside image_common

  1. Overview of camera_info_manager_py

    rolling
    The camera_info_manager_py package provides a Python interface for managing sensor_msgs/CameraInfo messages. It is designed for use in camera drivers written in Python, allowing them to handle camera calibration data similarly to the C++ camera_info_manager package. Note that while the functionality is similar, the Python interface is not identical to the C++ implementation.
  2. Overview of image_transport

    rolling

    The image_transport library provides a plugin-based architecture for publishing and subscribing to images. It allows applications to switch between raw and compressed formats transparently without changing the application code.

    Key features include:

    • Publishers: Publisher and CameraPublisher (for images with optional camera info).
    • Subscribers: Subscriber and CameraSubscriber (supports transport hints).
    • Filtering: SubscriberFilter for integration with message_filters.
    • Utilities: republish node for converting between transports and list_transports to see available plugins.
    • Support: Lifecycle node support and QoS overrides.
  3. Use camera_info_manager_py for camera calibration in ROS 2

    rolling

    The camera_info_manager_py package provides a Python interface for managing camera calibration data in ROS 2. It is designed for Python-based camera drivers that need to load sensor_msgs/msg/CameraInfo from disk, save new calibration data received via the set_camera_info service, and serve that calibration to the ROS 2 system.

    Key responsibilities include:

    • Loading calibration files from filesystem or package paths.
    • Saving updated calibration data.
    • Providing a service to allow external tools to update the driver's calibration.
  4. Use camera_info_manager to manage CameraInfo in camera drivers

    rolling

    The camera_info_manager package provides a C++ class designed for camera drivers to manage sensor_msgs/msg/CameraInfo.

    It automates three key tasks:

    1. Lazy Loading: Automatically loads calibration data from a file or a package:// URL the first time it is accessed.
    2. Saving: Saves new calibration data to the specified file when a sensor_msgs/srv/SetCameraInfo service call is received.
    3. Service Advertising: Automatically advertises the ~/set_camera_info service, allowing calibration tools (like camera_calibration) to update the driver's calibration data at runtime.

    Typical Workflow:

    • The driver node instantiates a CameraInfoManager with a calibration URL.
    • The manager waits for the first call to getCameraInfo() or isCalibrated() before performing I/O.
    • The driver then publishes both the Image and the CameraInfo on every frame.
  5. How image_transport works

    rolling

    image_transport is a plugin-based framework for publishing and subscribing to images in ROS 2. It provides a transparent layer over standard ROS 2 publishers and subscribers, allowing image data to be sent in various formats (e.g., raw, compressed, theora) without changing application code.

    Key Concepts:

    • Topic Families: For every base image topic (e.g., /camera/image_raw), the publisher advertises a family of topics including the raw topic and any installed transport plugins (e.g., /camera/image_raw/compressed).
    • Plugin-based Architecture: Transport plugins are discovered at runtime via pluginlib. The publisher creates one sub-publisher per installed plugin. The subscriber picks exactly one transport based on the image_transport parameter.
    • Minimal API Changes: The API is designed to be nearly identical to standard rclcpp publishers and subscribers.
    Camera driver
        │
        ▼
    image_transport::Publisher
        ├─ raw topic          ──► raw subscriber
        ├─ compressed topic   ──► compressed subscriber
        └─ theora topic       ──► theora subscriber
  6. How ImageTransport manages publishers and subscribers

    rolling

    The image_transport_py library follows a factory pattern where the ImageTransport class manages the creation and lifecycle of transport-specific communication objects.

    • ImageTransport: The central entry point. It handles the selection of transport plugins (like raw or compressed) based on initialization parameters.
    • Publishers (Publisher / CameraPublisher): Created via advertise(). They wrap the logic for sending data over the chosen transport. CameraPublisher specifically handles the dual-stream requirement of images and camera info.
    • Subscribers (Subscriber / CameraSubscriber): Created via subscribe(). They handle the reception of data. Because image_transport can use different plugins for the same base topic, subscribers can query get_transport() to identify which plugin is currently delivering data.

    This architecture allows Python developers to benefit from efficient, plugin-based image transport (reducing overhead compared to standard ROS 2 topics) while maintaining a clean, object-oriented interface.

  7. Supported camera calibration file formats

    rolling

    The library supports two human-readable formats:

    1. YAML (.yaml or .yml): The standard format produced by the ROS 2 camera_calibration package and used by camera_info_manager. It contains fields such as image_width, image_height, camera_matrix, distortion_model, and projection_matrix.

    2. Videre INI (.ini): A legacy format used by older Videre Design stereo cameras. The parser supports the subset of this format commonly used in open-source camera drivers.

  8. Integrate image_transport with message_filters

    rolling

    If you need to synchronize image streams with other sensor data (like PointCloud2) using message_filters synchronization policies (e.g., TimeSynchronizer or ApproximateTime), use image_transport::SubscriberFilter.

    image_transport::SubscriberFilter acts as a drop-in replacement for message_filters::Subscriber. Its primary advantage is that it automatically decodes compressed image streams before passing them into the message_filters synchronization chain, allowing you to work with standard sensor_msgs::msg::Image types even if the source is compressed.

  9. Use the camera_calibration_parsers high-level API

    rolling

    The camera_calibration_parsers package provides C++ functions to read and write camera calibration data. For most use cases, you should use the high-level API provided in parse.hpp. This layer automatically detects whether a file is in YAML format (standard for ROS 2 camera_calibration) or Videre INI format (legacy) based on the file extension.

    The API supports three types of operations:

    • write: Serializes a sensor_msgs/msg/CameraInfo to a stream or file.
    • read: Deserializes from a stream or file into a CameraInfo.
    • parse: Deserializes from an in-memory string buffer.
    // Use parse.hpp for automatic format detection
    #include <camera_calibration_parsers/parse.hpp>
    
    // Example logic (conceptual):
    // camera_calibration_parsers::read(file_path, camera_info_msg);
    // camera_calibration_parsers::write(file_path, camera_info_msg);
  10. Use the set_camera_info ROS 2 service

    rolling

    When you instantiate a CameraInfoManager, it automatically advertises a set_camera_info service relative to the node's namespace (or an optional custom namespace prefix).

    This service allows external calibration tools to send new calibration data to your running driver. When the service is called, the manager:

    1. Updates the in-memory CameraInfo.
    2. Saves the new data to the configured calibration URL.
  11. How image_transport plugins work

    rolling

    An image_transport plugin is a pair of pluginlib plugins—one publisher and one subscriber—that work together to negotiate how image data is serialized on the wire.

    When a publisher uses a specific transport, it encodes the standard sensor_msgs/msg/Image into a transport-specific message type. The corresponding subscriber plugin listens to that specific message type and decodes it back into a standard sensor_msgs/msg/Image before passing it to the user's callback.

  12. Understand CameraPublisher topic naming conventions

    rolling

    When using image_transport::CameraPublisher, the CameraInfo topic is automatically derived from the base image topic name by appending /../camera_info. This creates a sibling topic.

    For example, if your base topic is /camera/image_raw:

    • Image topic: /camera/image_raw
    • Camera info topic: /camera/camera_info

    You can programmatically compute this sibling name using the image_transport::getCameraInfoTopic function.