extractor.hpp
Go to the documentation of this file.
00001 
00006 #ifndef _THERMALVIS_EXTRACTOR_H_
00007 #define _THERMALVIS_EXTRACTOR_H_
00008         
00009 #include "ros_resources.hpp"
00010 #include "general_resources.hpp"
00011 #include "opencv_resources.hpp"
00012 #include "tools.hpp"
00013 #include "improc.hpp"
00014 
00015 #include <dynamic_reconfigure/server.h>
00016 #include "extractorConfig.h"
00017 
00018 #include <rosbag/bag.h>
00019 #include <rosbag/view.h>
00020 
00021 #include <message_filters/subscriber.h>
00022 #include <message_filters/synchronizer.h>
00023 #include <message_filters/sync_policies/approximate_time.h>
00024 
00025 #include <opencv/cv.h>
00026 #include <opencv/highgui.h>
00027 
00028 #include <cv_bridge/cv_bridge.h> 
00029 #include <image_transport/image_transport.h>
00030 
00031 #include <boost/foreach.hpp>
00032 #include "boost/filesystem.hpp"  
00033 #include <time.h>
00034 #include <math.h>
00035 
00036 #include "ros/ros.h"
00037 #include "sensor_msgs/Image.h"
00038 #include "sensor_msgs/CameraInfo.h"
00039 
00040 #include <iostream>
00041 #include <fstream>
00042 
00043 #define SAVEPLY false
00044 #define FILTER_DISTANCE 1
00045 #define SIGMA_P 15
00046 #define SIGMA_R .05
00047 
00048 #define MAX_BAGS 200
00049 
00050 #define DEFAULT_MAX_TIMESTAMP_DIFF      0.01
00051 
00052 const char __PROGRAM__[] = "EXTRACTOR";
00053 using namespace cv;
00055 struct extractorData {
00056         
00057         string bagSource, outputFolder;
00058         
00059         bool debugMode, verboseMode;
00060         
00061         bool internalTimestamp, thermistorReading, recordDuplicates, undistortThermal;
00062         
00063         bool setupForMapping;
00064         
00065         bool splitBags;
00066         
00067         string thermalIntrinsics;
00068         
00069         int maxFrames;
00070         
00071         string rgbTopic;
00072         string depthTopic;
00073         string thermalTopic;
00074         
00075         bool rawTimeFormat;
00076         
00077         // Intra-determined variables
00078         
00079         bool wantsThermal, wantsRgb, wantsDepth;
00080         
00081         string rgbInfoTopic;
00082         string depthInfoTopic;
00083         string thermalInfoTopic;
00084         
00085         string read_addr;
00086         
00087         bool obtainStartingData(ros::NodeHandle& nh);  
00088         
00089 };
00090 
00092 class extractorNode {
00093 private:
00094 
00095         ros::NodeHandle *ref;
00096         
00097         // cam-calib
00098         Mat imageSize, cameraMatrix, distCoeffs, newCamMat;
00099         Size cameraSize;
00100         Mat map1, map2;
00101 
00102         
00103         Mat oldThermal;
00104         
00105         rosbag::Bag bag[MAX_BAGS];
00106         
00107         vector<string> splitBagNames;
00108         
00109         float *writeData;
00110         
00111         extractorData configData;
00112         
00113         bool stillListening;
00114         
00115         ofstream ofs_thermistor_log;
00116         string thermistorLogFile;
00117         
00118         ros::NodeHandle private_node_handle;
00119         
00120         char nodeName[256];
00121         
00122         dynamic_reconfigure::Server<thermalvis::extractorConfig> server;
00123         dynamic_reconfigure::Server<thermalvis::extractorConfig>::CallbackType f;
00124         
00125         float** ApplyBilateralFilter(float** data, const int width, const int height, float sigmaP, float sigmaR);
00126         
00127         FILE *dataFile, *timeFile, *depthtimeFile, *depthInternaltimeFile, *imgtimeFile, *imgInternaltimeFile, *thermaltimeFile, *thermalInternaltimeFile, *thermalDuplicatesFile;
00128         
00129         int count;
00130         int filenum;
00131         double startTime;
00132         int skipFrames;
00133         int maxFrames;
00134 
00135         float d_fx;
00136         float d_fy;
00137         float d_cx;
00138         float d_cy;
00139         
00140   char *outputFilename;
00141   char *outputFilenameThermal;
00142   char *outputdepth, *outputcloud ;
00143   
00144   stringstream imgPath;
00145     stringstream timePath;
00146     stringstream imgtimePath, imgInternaltimePath, depthtimePath, depthInternaltimePath, thermaltimePath, thermalInternaltimePath, thermalDuplicatesPath;
00147     
00148     // Image topics to load
00149   std::vector<std::string> topics;
00150   
00151   
00152   
00153   int count_rgb; 
00154   int count_depth;
00155   int count_rgbinfo; 
00156   int count_depthinfo;
00157   int count_thermal;
00158   int count_thermalinfo;
00159   
00160   sensor_msgs::Image::ConstPtr rgbImg;
00161   sensor_msgs::CameraInfo::ConstPtr rgbInfo;
00162   sensor_msgs::Image::ConstPtr depthImg;
00163   sensor_msgs::CameraInfo::ConstPtr depthInfo;
00164   sensor_msgs::Image::ConstPtr thermalImg;
00165   sensor_msgs::CameraInfo::ConstPtr thermalInfo;
00166   
00167         
00168 public:
00169 
00170         rosbag::View *view;
00171 
00172         extractorNode(ros::NodeHandle& nh, extractorData startupData);
00173         ~extractorNode();
00174         
00175         void makeDirectories();
00176         
00177         bool isStillListening();
00178         
00179         void serverCallback(thermalvis::extractorConfig &config, uint32_t level);
00180         
00181         
00182         
00183         void extractBagFile();
00184         void cameraCallback(const sensor_msgs::Image::ConstPtr& rgbImgMsg,
00185                                           const sensor_msgs::Image::ConstPtr& depthImgMsg,
00186                                           const sensor_msgs::Image::ConstPtr& thermalImgMsg,
00187                                           const sensor_msgs::CameraInfo::ConstPtr& rgbInfoMsg,
00188                                           const sensor_msgs::CameraInfo::ConstPtr& depthInfoMsg,
00189                                           const sensor_msgs::CameraInfo::ConstPtr& thermalInfoMsg
00190                                           );
00191 };
00192 
00193 typedef message_filters::sync_policies::ApproximateTime< sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::CameraInfo, sensor_msgs::CameraInfo, sensor_msgs::CameraInfo > SyncPolicy;
00194 
00199 template <class M>
00200 class BagSubscriber : public message_filters::SimpleFilter<M>
00201 {
00202 public:
00203   void newMessage(const boost::shared_ptr<M const> &msg)
00204   {
00205     signalMessage(msg);
00206   }
00207 };
00208 
00209 #endif


thermalvis
Author(s): Stephen Vidas
autogenerated on Sun Jan 5 2014 11:38:44