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.3.1"
or you can use cargo to add the dependency:
bash
cargo add cv_bridge
``` rust use opencv::{ prelude::*, highgui, }; use rosrustmsg::{ sensormsgs::Image, stdmsgs::Header }; use cvbridge::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();
} ```