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
Add the following to your Cargo.toml file under dependencies:
toml
[dependencies]
cv-bridge = "0.2.0"
or you can use cargo to add the dependency:
bash
cargo add cv_bridge
```rust use cvbridge::CvImage; use rosrust::sensormsgs::Image; use opencv::prelude::*;
fn main() { # Convert from ROS image message to OpenCV image let rosimage = Image::default(); let cvimage = CvImage::fromimgmsg(rosimage); let mat = cvimage.ascvmat("rgb8".to_string());
# Convert from OpenCV image to ROS image message
let cv_image = CvImage::from_cvmat(mat);
let ros_image = cv_image.into_imgmsg();
} ```
```rust use cvbridge::CvImage; use rosrust::sensormsgs::Image; use image::DynamicImage;
fn main() { # Convert from ROS image message to let rosimage = Image::default(); let cvimage = CvImage::fromimgmsg(rosimage);
# Using the underlying DynamicImage type
let image = cv_image.as_image(); # Returns a immutable reference to the underlying DynamicImage
let image = cv_image.as_mut_image(); # Returns a mutable reference to the underlying DynamicImage
} ```
```rust use cv_bridge::CvImage; use std::vec;
fn main() {
let bytes:Vec