How to convert an an opencv image using cvBridge??
How do I convert an image I have opened through opencv into sensor_msgs/image??
How do I convert an image I have opened through opencv into sensor_msgs/image??
I recommend the cv_bridge tutorials.
Here is a snippet of code I have used to do this and the full code is here. It is a package that also uses opencv to grab images and publish them. Some of the variables are:
image_transport::ImageTransport transport;
image_transport::CameraPublisher image_pub;
camera_info_manager::CameraInfoManager info_mgr;
And the code:
// if subscribers, pub images
if(image_pub.getNumSubscribers() > 0) {
ros::Time time = ros::Time::now();
// convert OpenCV image to ROS message
cv_bridge::CvImage cvi;
cvi.header.stamp = time;
cvi.header.frame_id = "image";
cvi.encoding = "bgr8";
cvi.image = cv_image;
// get camera parameters
sensor_msgs::CameraInfo info = info_mgr.getCameraInfo();
info.header.stamp = cvi.header.stamp;
info.header.frame_id = cvi.header.frame_id; // whatever it is called
info.width = cv_image.cols;
info.height = cv_image.rows;
sensor_msgs::Image im;
cvi.toImageMsg(im);
image_pub.publish(im,info);
}
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2012-04-28 05:12:45 -0600
Seen: 4,284 times
Last updated: Apr 28 '12
Error in using cv_bridge: communication ROS - OpenCV
cv_bridge doesn't set 'step' properly
cv_bridge tutorials problems using ardrone_autonomy
cv_bridge tutorial example not compiling in ROS Kinetic and Ubuntu 16.04
cv_bridge give me darker images [closed]
Is ROS Kinetic compatible with libopencv-dev-2.4.9?
Cannot build cv_bridge for ROS Jade on OSX Yosemite [closed]
OpenNi: save /came/depth/image_raw to PGM 11 bit? [closed]
Error when converting IR kinect image to CvImage using cv_bridge
If either of these answers answered your question, please mark one as "correct" so this questions gets closed out ... thanks!