Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030 #include <string.h>
00031 #include <ros/ros.h>
00032 #include <nodelet/nodelet.h>
00033 #include <sensor_msgs/Image.h>
00034 #include <image_transport/image_transport.h>
00035 #include <cv_bridge/cv_bridge.h>
00036
00037 #include <boost/make_shared.hpp>
00038
00039 using namespace cv_bridge;
00040 using namespace cv;
00041
00042 #define LB_WIDTH 512
00043 #define LB_HEIGHT 384
00044 #define NUM_IMGS 6
00045
00046 #include <lrm_camera_drivers/split_node.h>
00047
00048 namespace lrm_camera_drivers {
00049
00050 class SplitLadybugNodelet: public nodelet::Nodelet {
00051
00052 image_transport::Subscriber sub_;
00053 boost::shared_ptr<image_transport::ImageTransport> it_;
00054
00055 image_transport::Publisher pub[NUM_IMGS];
00056
00057
00058 virtual void onInit();
00059
00060 void imageCb(const sensor_msgs::ImageConstPtr& raw_msg);
00061 };
00062
00063 void SplitLadybugNodelet::onInit() {
00064
00065 ros::NodeHandle &nh = getNodeHandle();
00066 ros::NodeHandle &nh_priv = getPrivateNodeHandle();
00067
00068 it_.reset(new image_transport::ImageTransport(nh));
00069
00070 image_transport::TransportHints hints("raw", ros::TransportHints(), nh);
00071 sub_ = it_->subscribe("camera/image_raw", 1, &SplitLadybugNodelet::imageCb, this, hints);
00072
00073 pub[0] = it_->advertise("/camera/image_color/0", 1);
00074 pub[1] = it_->advertise("/camera/image_color/1", 1);
00075 pub[2] = it_->advertise("/camera/image_color/2", 1);
00076 pub[3] = it_->advertise("/camera/image_color/3", 1);
00077 pub[4] = it_->advertise("/camera/image_color/4", 1);
00078 pub[5] = it_->advertise("/camera/image_color/5", 1);
00079
00080 }
00081
00082 void SplitLadybugNodelet::imageCb(const sensor_msgs::ImageConstPtr& msg) {
00083 bool have_subsc = false;
00084 for (int i = 0; i < NUM_IMGS; i++) {
00085 if (pub[i].getNumSubscribers() > 0) {
00086 have_subsc = true;
00087 break;
00088 }
00089 }
00090 if (have_subsc) {
00091 try {
00092 cv_bridge::CvImageConstPtr cv_ptr;
00093 cv_ptr = toCvShare(msg, "mono8");
00094 int sz = 0;
00095
00096 sensor_msgs::Image omsg;
00097 omsg.header.frame_id = "/ladybug";
00098 omsg.header.seq = msg->header.seq;
00099 omsg.header.stamp = msg->header.stamp;
00100
00101 for (int i = 0; i < NUM_IMGS; i++) {
00102
00103 const cv::Mat_<uint8_t> img_0(LB_HEIGHT, LB_WIDTH, const_cast<uint8_t*>(&msg->data[sz]), msg->step);
00104 sz += (LB_WIDTH * LB_HEIGHT);
00105 const cv::Mat_<uint8_t> img_1(LB_HEIGHT, LB_WIDTH, const_cast<uint8_t*>(&msg->data[sz]), msg->step);
00106 sz += (LB_WIDTH * LB_HEIGHT);
00107 const cv::Mat_<uint8_t> img_2(LB_HEIGHT, LB_WIDTH, const_cast<uint8_t*>(&msg->data[sz]), msg->step);
00108 sz += (LB_WIDTH * LB_HEIGHT);
00109 const cv::Mat_<uint8_t> img_3(LB_HEIGHT, LB_WIDTH, const_cast<uint8_t*>(&msg->data[sz]), msg->step);
00110 sz += (LB_WIDTH * LB_HEIGHT);
00111
00112 if (pub[i].getNumSubscribers() > 0) {
00113 omsg.width = LB_HEIGHT;
00114 omsg.height = LB_WIDTH;
00115 omsg.encoding = "rgb8";
00116 omsg.is_bigendian = false;
00117 omsg.step = omsg.width * 3;
00118 omsg.data.resize(LB_WIDTH * LB_HEIGHT * 3);
00119 CvImagePtr cp = toCvCopy(omsg, "rgb8");
00120 Mat src[] = { img_3, img_1, img_0 };
00121 cv::merge(src, 3, cp->image);
00122 pub[i].publish(cp->toImageMsg());
00123 }
00124 }
00125 } catch (cv_bridge::Exception& e) {
00126
00127 }
00128 }
00129 }
00130
00131 };
00132
00133 #include <pluginlib/class_list_macros.h>
00134 PLUGINLIB_EXPORT_CLASS(lrm_camera_drivers::SplitLadybugNodelet, nodelet::Nodelet)