Crate cv_bridge

source ·
Expand description

cv-bridge is a crate for converting between OpenCV and ROS Image. This works in conjunction to the ros_rust crate.

Crate Status

  • Currently only supports the standard CV encodings
  • Currently only supports CV_8U and CV_16U channel depths
  • Does not support compressed images

Examples

Convert from ROS Image to OpenCV Mat

use opencv::highgui;
use cv_bridge::{
    CvImage,
    msgs::sensor_msgs::Image,
};
fn main() {
    // Initialize ros node
    rosrust::init("image_viewer");
 
    // Create image subscriber
    let _subscriber_raii = rosrust::subscribe(
        "/camera/image_raw",
        5,
        move |image: Image| {
            // Convert ros Image to opencv Mat
            let mut cv_image = CvImage::from_imgmsg(image).expect("failed to construct CvImage from ros Image"); 
            let mat = cv_image.as_cvmat().expect("failed to convert CvImage to Mat");
 
            // Display image
            let window = "view";
            highgui::named_window(window, highgui::WINDOW_AUTOSIZE).unwrap();
            highgui::imshow(window, &mat).unwrap();
            highgui::wait_key(1).unwrap();
        }
    );
    rosrust::spin();
}

Re-exports

pub use cv_image::CvImage;

Modules

cv_image module contains CvImage struct and its methods. CvImage wraps the image array and its metadata and acts as a bridge between the sensor_msgs::Image message and cv::Mat
Manually generated ros messages
Utilities for image processing