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 <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         /*bool ros2mrpt(const sensor_msgs::Image &msg,  CObservationImage &obj)
00046         {
00047             CvImage *frame1 = cv_bridge::toCvCopy(msg, "bgr8").get(); //CvShare(msg,"bgr8").image;
00048 
00049         }
00050 */
00051         /************************************************************************
00052         *                                               mrpt2ros                                                                *
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 std_msgs/Header header
00101 uint32 height
00102 uint32 width
00103 string encoding
00104 uint8 is_bigendian
00105 uint32 step
00106 uint8[] data
00107  */


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Fri Apr 27 2018 05:10:54