cv-bridge 0.3.1

Rust implemenation of cv_bridge that converts between ROS image messages and OpenCV images
docs.rs failed to build cv-bridge-0.3.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: cv-bridge-0.3.3

cv-bridge-rs

Crates.io Docs.rs

Rust implemenation of cv_bridge that converts between ROS image messages and OpenCV images

Warning: This package is still under active development. Use at your own risk.

Getting Started

Adding cv_bridge to your project

Add the following to your Cargo.toml file under dependencies:

[dependencies]
cv-bridge = "0.3.1"

or you can use cargo to add the dependency:

cargo add cv_bridge

Converting between ROS image messages and OpenCV images

use opencv::{
    prelude::*,
    highgui,
};
use rosrust_msg::{
    sensor_msgs::Image,
    std_msgs::Header
};
use cv_bridge::CvImage;

fn main() {
    // Initialize ROS node
    rosrust::init("image_listener");

    // Create a subscription to the /camera/image_raw topic
    let _subscriber_raii = rosrust::subscribe(
        "/camera/image_raw", 
        1, 
        move |ros_image: Image| {
            // Create a CvImage from the ROS image message
            let mut cv_image = CvImage::from_imgmsg(ros_image).unwrap();

            // Create opencv::core::Mat from the CvImage
            let mat = cv_image.as_cvmat().unwrap();

            // Display the image
            highgui::imshow("image", &mat).unwrap();
            highgui::wait_key(1).unwrap();
        }
    ).unwrap();

    rosrust::spin();
}

Features

  • Covert to and from sensor_msgs/Image and opencv::core::Mat
  • Support for various encodings defined by sensor_msgs: image_encodings.h crate
  • Support for 8-bit and 16-bit depth channels
  • Support for 32-bit and 64-bit depth channels
  • Documentation and examples
  • Covert to and from sensor_msgs/CompressedImage and opencv::core::Mat