image_reader_alg_node.cpp
Go to the documentation of this file.
00001 #include "image_reader_alg_node.h"
00002 
00003 ImageReaderAlgNode::ImageReaderAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<ImageReaderAlgorithm>(),
00005   it_(this->public_node_handle_),
00006   iit_database(0),
00007   tf_listener_(ros::Duration(30.f)), list_pointer(0)
00008 {
00009   //init class attributes if necessary
00010   this->loop_rate_ = 10;//in [Hz]
00011 
00012   // [init publishers]
00013   image_pub_ = it_.advertiseCamera("image_raw", 100);
00014  
00015   // [init subscribers]
00016   
00017   // [init services]
00018   
00019   // [init clients]
00020   
00021   // [init action servers]
00022   
00023   // [init action clients]
00024 //  init_sensor_info();
00025 }
00026 
00027 ImageReaderAlgNode::~ImageReaderAlgNode(void)
00028 {
00029   // [free dynamic memory]
00030 }
00031 
00032 void ImageReaderAlgNode::mainNodeThread(void)
00033 {
00034   // [fill msg structures]
00035   if (iit_database < 2157) //database length
00036   update_msgs();  
00037   
00038   // [fill srv structure and make request to the server]
00039   
00040   // [fill action structure and make request to the action server]
00041 
00042   // [publish messages]
00043   sensor_msgs::Image image_;
00044   this->img_msg_.toImageMsg( image_ );
00045   this->image_pub_.publish( image_,  this->CameraInfo_msg_ );
00046 
00047 }
00048 
00049 void ImageReaderAlgNode::init_sensor_info()
00050 {
00051         //Image
00052         img_msg_.header.frame_id = "/camera";
00053 
00054         //      Camera Info -----------------------------------------------------
00055         CameraInfo_msg_.height = 960;//480 ;
00056         CameraInfo_msg_.width = 1280;//640;
00057         CameraInfo_msg_.distortion_model = "plumb_bob";
00058 
00059         CameraInfo_msg_.D.clear();
00060         CameraInfo_msg_.D.push_back(0);
00061         CameraInfo_msg_.D.push_back(0);
00062         CameraInfo_msg_.D.push_back(0);
00063         CameraInfo_msg_.D.push_back(0);
00064         CameraInfo_msg_.D.push_back(0);
00065 
00066         CameraInfo_msg_.K[0] =  0;
00067         CameraInfo_msg_.K[2] = 0;
00068         CameraInfo_msg_.K[4] =  0;
00069         CameraInfo_msg_.K[5] = 0;
00070         CameraInfo_msg_.K[8] = 0;
00071 
00072 // float64[9] CameraInfo_msg_.R
00073         CameraInfo_msg_.R[0] =  0;
00074         CameraInfo_msg_.R[4] =  0;
00075         CameraInfo_msg_.R[8] =  0;
00076 
00077 // float64[12] CameraInfo_msg_.P := K *[R | t]
00078         CameraInfo_msg_.P[0] =  0*0;
00079         CameraInfo_msg_.P[2] = 0*0;
00080         CameraInfo_msg_.P[5] =  0*0;
00081         CameraInfo_msg_.P[6] = 0*0;
00082         CameraInfo_msg_.P[10] = 1;
00083 
00084         CameraInfo_msg_.header.frame_id = "/camera";
00085     cam_model_.fromCameraInfo(CameraInfo_msg_);
00086 }
00087 
00088 void ImageReaderAlgNode::update_msgs()
00089 {
00090   cv::Mat outIm;
00091   ros::Time now = ros::Time::now();
00092   iit_database ++;
00093   //    Header
00094   CameraInfo_msg_.header.seq   = iit_database;
00095   CameraInfo_msg_.header.stamp = now;
00096   img_msg_.header.seq          = iit_database;
00097   img_msg_.header.stamp        = now;
00098 
00099   //Image --------------------------------------------------------
00100   std::string fileString = path + "/list.lst";
00101   FILE * file_out;
00102   file_out = fopen (  fileString.c_str() , "r");
00103   fseek(file_out , list_pointer*(iit_database -1) , SEEK_SET );
00104   char file_name[32];
00105   if (fscanf(file_out, "%s\n" , file_name) != EOF) { 
00106     std::string string_file_name = file_name;
00107 //  ROS_INFO("%s",string_file_name.c_str()); 
00108     fileString = path + string_file_name; //list.lst -> listed all file names...
00109     outIm = cv::imread( fileString.c_str(), 1 );
00110     img_msg_.encoding = "bgr8";
00111     img_msg_.image    = outIm;
00112   }
00113   
00114   if (list_pointer == 0)
00115     list_pointer = strlen(file_name) + 1;
00116   fclose(file_out);
00117 }
00118 
00119 
00120 
00121 /*  [subscriber callbacks] */
00122 
00123 /*  [service callbacks] */
00124 
00125 /*  [action callbacks] */
00126 
00127 /*  [action requests] */
00128 
00129 void ImageReaderAlgNode::node_config_update(Config &config, uint32_t level)
00130 {
00131   ROS_DEBUG("MyDatabasePublAlgNode::node_config_update");
00132   this->alg_.lock();
00133         iit_database = config.sequence_iterator;
00134         loop_rate_   = config.frame_rate;
00135         path   = config.images_path;
00136 
00137   this->alg_.unlock();
00138 }
00139 
00140 void ImageReaderAlgNode::addNodeDiagnostics(void)
00141 {
00142 }
00143 
00144 /* main function */
00145 int main(int argc,char *argv[])
00146 {
00147   return algorithm_base::main<ImageReaderAlgNode>(argc, argv, "image_reader_alg_node");
00148 }


iri_image_reader
Author(s): Àngel Sanatamaria Navarro
autogenerated on Fri Dec 6 2013 21:32:49