Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "mrpt_bridge/stereo_image.h"
00017
00018
00019
00020 #include "ros/ros.h"
00021 #include "mrpt_bridge/image.h"
00022 #include <opencv/highgui.h>
00023 #include <cv_bridge/cv_bridge.h>
00024
00025 #include <sensor_msgs/Image.h>
00026 #include <sensor_msgs/image_encodings.h>
00027
00028 #include <mrpt/version.h>
00029 #if MRPT_VERSION>=0x199
00030 using namespace mrpt::img;
00031 #else
00032 using namespace mrpt::utils;
00033 #endif
00034
00035 using namespace ros;
00036 using namespace sensor_msgs;
00037 using namespace cv;
00038 using namespace cv_bridge;
00039
00040
00041 namespace mrpt_bridge
00042 {
00043 namespace stereo_image
00044 {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 bool mrpt2ros(const CObservationStereoImages &obj,const std_msgs::Header &msg_header,
00055 sensor_msgs::Image &left, sensor_msgs::Image &right,
00056 stereo_msgs::DisparityImage &disparity)
00057 {
00058
00060 CImage temp_img = obj.imageLeft;
00061 Mat cvImg = cv::cvarrToMat(temp_img.getAs<IplImage>());
00062 cv_bridge::CvImage img_bridge;
00063 img_bridge = CvImage(left.header, sensor_msgs::image_encodings::BGR8, cvImg);
00064 img_bridge.toImageMsg(left);
00065 left.encoding = "bgr8";
00066 left.header = msg_header;
00067 left.height = (int) obj.imageLeft.getHeight();
00068 left.width = (int) obj.imageRight.getWidth();
00069
00071 CImage temp_img2 = obj.imageRight;
00072 Mat cvImg2 = cv::cvarrToMat(temp_img2.getAs<IplImage>());
00073 cv_bridge::CvImage img_bridge2;
00074 img_bridge2 = CvImage(right.header, sensor_msgs::image_encodings::BGR8, cvImg2);
00075 img_bridge2.toImageMsg(right);
00076 right.encoding = "bgr8";
00077 right.header = msg_header;
00078 right.height = (int) obj.imageLeft.getHeight();
00079 right.width = (int) obj.imageRight.getWidth();
00080
00081 if(obj.hasImageDisparity)
00082 {
00083 CImage temp_disp = obj.imageDisparity;
00084 Mat cvImg3 = cv::cvarrToMat(temp_disp.getAs<IplImage>());
00085 cv_bridge::CvImage img_bridge3;
00086 img_bridge3 = CvImage(disparity.header, sensor_msgs::image_encodings::BGR8, cvImg3);
00087 img_bridge3.toImageMsg(disparity.image);
00088 disparity.image.encoding = "bgr8";
00089 disparity.image.header = msg_header;
00090 disparity.image.height = (int) obj.imageDisparity.getHeight();
00091 disparity.image.width = (int) obj.imageDisparity.getWidth();
00092 }
00093 return true;
00094 }
00095 }
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107