camera_info_publisher.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2017 Roboception GmbH
00003  * All rights reserved
00004  *
00005  * Author: Heiko Hirschmueller
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright notice,
00011  * this list of conditions and the following disclaimer.
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright notice,
00014  * this list of conditions and the following disclaimer in the documentation
00015  * and/or other materials provided with the distribution.
00016  *
00017  * 3. Neither the name of the copyright holder nor the names of its contributors
00018  * may be used to endorse or promote products derived from this software without
00019  * specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031  * POSSIBILITY OF SUCH DAMAGE.
00032  */
00033 
00034 #include "camera_info_publisher.h"
00035 
00036 #include <rc_genicam_api/pixel_formats.h>
00037 
00038 namespace rc
00039 {
00040 
00041 CameraInfoPublisher::CameraInfoPublisher(ros::NodeHandle &nh, std::string frame_id_prefix,
00042                                          double _f, double t, bool left)
00043         : GenICam2RosPublisher(frame_id_prefix)
00044 {
00045   f=_f;
00046 
00047   // prepare camera info message
00048 
00049   info.header.frame_id=frame_id;
00050 
00051   info.width=0;
00052   info.height=0;
00053   info.distortion_model="plumb_bob"; // we have to choose a model
00054   info.D.resize(5); // all 0, since images are rectified
00055 
00056   info.K[0]=1; info.K[1]=0; info.K[2]=0;
00057   info.K[3]=0; info.K[4]=1; info.K[5]=0;
00058   info.K[6]=0; info.K[7]=0; info.K[8]=1;
00059 
00060   info.R[0]=1; info.R[1]=0; info.R[2]=0;
00061   info.R[3]=0; info.R[4]=1; info.R[5]=0;
00062   info.R[6]=0; info.R[7]=0; info.R[8]=1;
00063 
00064   info.P[0]=1; info.P[1]=0; info.P[2]=0; info.P[3]=0;
00065   info.P[4]=0; info.P[5]=1; info.P[6]=0; info.P[7]=0;
00066   info.P[8]=0; info.P[9]=0; info.P[10]=1; info.P[11]=0;
00067 
00068   info.binning_x=1;
00069   info.binning_y=1;
00070 
00071   // advertise topic
00072 
00073   if (left)
00074   {
00075     pub=nh.advertise<sensor_msgs::CameraInfo>("left/camera_info", 1);
00076   }
00077   else
00078   {
00079     pub=nh.advertise<sensor_msgs::CameraInfo>("right/camera_info", 1);
00080     info.P[3]=t;
00081   }
00082 }
00083 
00084 bool CameraInfoPublisher::used()
00085 {
00086   return pub.getNumSubscribers() > 0;
00087 }
00088 
00089 void CameraInfoPublisher::publish(const rcg::Buffer *buffer, uint64_t pixelformat)
00090 {
00091   if (pub.getNumSubscribers() > 0 && (pixelformat == Mono8 || pixelformat == YCbCr411_8))
00092   {
00093     const uint64_t freq=1000000000ul;
00094     uint64_t time=buffer->getTimestampNS();
00095 
00096     info.header.seq++;
00097     info.header.stamp.sec=time/freq;
00098     info.header.stamp.nsec=time-freq*info.header.stamp.sec;
00099 
00100     info.width=static_cast<uint32_t>(buffer->getWidth());
00101     info.height=static_cast<uint32_t>(buffer->getHeight());
00102 
00103     if (info.height > info.width)
00104     {
00105       info.height>>=1; // left and right images are stacked together
00106     }
00107 
00108     info.K[0]=info.K[4]=f*info.width;
00109     info.P[0]=info.P[5]=f*info.width;
00110 
00111     info.P[2]=info.K[2]=info.width/2.0;
00112     info.P[6]=info.K[5]=info.height/2.0;
00113 
00114     pub.publish(info);
00115   }
00116 }
00117 
00118 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:01