stereo_image.cpp
Go to the documentation of this file.
00001 /* +------------------------------------------------------------------------+
00002    |                     Mobile Robot Programming Toolkit (MRPT)            |
00003    |                          http://www.mrpt.org/                          |
00004    |                                                                        |
00005    | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file     |
00006    | See: http://www.mrpt.org/Authors - All rights reserved.                |
00007    | Released under BSD License. See details in http://www.mrpt.org/License |
00008    +------------------------------------------------------------------------+ */
00009 
00010 /*---------------------------------------------------------------
00011         APPLICATION: mrpt_ros bridge
00012         FILE: stereo_image.cpp
00013         AUTHOR: Raghavender Sahdev <raghavendersahdev@gmail.com>
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 <mrpt/utils.h>
00023 #include <opencv/highgui.h>
00024 #include <cv_bridge/cv_bridge.h>
00025 
00026 #include <sensor_msgs/Image.h>
00027 #include <sensor_msgs/image_encodings.h>
00028 
00029 using namespace ros;
00030 using namespace sensor_msgs;
00031 using namespace cv;
00032 using namespace mrpt::utils;
00033 using namespace cv_bridge;
00034 
00035 
00036 namespace mrpt_bridge
00037 {
00038     namespace stereo_image
00039     {
00040         /*bool ros2mrpt(const sensor_msgs::Image &msg,  CObservationImage &obj)
00041         {
00042             CvImage *frame1 = cv_bridge::toCvCopy(msg, "bgr8").get(); //CvShare(msg,"bgr8").image;
00043 
00044         }
00045 */
00046         /************************************************************************
00047         *                                               mrpt2ros                                                                *
00048         ************************************************************************/
00049          bool mrpt2ros(const CObservationStereoImages &obj,const std_msgs::Header &msg_header,
00050                       sensor_msgs::Image &left, sensor_msgs::Image &right,
00051                       stereo_msgs::DisparityImage &disparity)
00052         {
00053 
00055             CImage temp_img = obj.imageLeft;
00056             Mat cvImg = cv::cvarrToMat(temp_img.getAs<IplImage>());
00057             cv_bridge::CvImage img_bridge;
00058             img_bridge = CvImage(left.header, sensor_msgs::image_encodings::BGR8, cvImg);
00059             img_bridge.toImageMsg(left);
00060             left.encoding = "bgr8";
00061             left.header = msg_header;
00062             left.height = (int) obj.imageLeft.getHeight();
00063             left.width = (int) obj.imageRight.getWidth();
00064 
00066             CImage temp_img2 = obj.imageRight;
00067             Mat cvImg2 = cv::cvarrToMat(temp_img2.getAs<IplImage>());
00068             cv_bridge::CvImage img_bridge2;
00069             img_bridge2 = CvImage(right.header, sensor_msgs::image_encodings::BGR8, cvImg2);
00070             img_bridge2.toImageMsg(right);
00071             right.encoding = "bgr8";
00072             right.header = msg_header;
00073             right.height = (int) obj.imageLeft.getHeight();
00074             right.width = (int) obj.imageRight.getWidth();
00075 
00076             if(obj.hasImageDisparity)
00077             {
00078                 CImage temp_disp = obj.imageDisparity;
00079                 Mat cvImg3 = cv::cvarrToMat(temp_disp.getAs<IplImage>());
00080                 cv_bridge::CvImage img_bridge3;
00081                 img_bridge3 = CvImage(disparity.header, sensor_msgs::image_encodings::BGR8, cvImg3);
00082                 img_bridge3.toImageMsg(disparity.image);
00083                 disparity.image.encoding = "bgr8";
00084                 disparity.image.header = msg_header;
00085                 disparity.image.height = (int) obj.imageDisparity.getHeight();
00086                 disparity.image.width = (int) obj.imageDisparity.getWidth();
00087             }
00088             return true;
00089         }
00090     }
00091 }
00092 
00093 //
00094 /*
00095 std_msgs/Header header
00096 uint32 height
00097 uint32 width
00098 string encoding
00099 uint8 is_bigendian
00100 uint32 step
00101 uint8[] data
00102  */


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Mon Sep 18 2017 03:12:06