33 #include <rosbag/bag.h>
35 #include <opencv2/highgui/highgui.hpp>
36 #include <opencv2/opencv.hpp>
38 #include <sensor_msgs/Image.h>
39 #include <sensor_msgs/CompressedImage.h>
40 #include <sensor_msgs/CameraInfo.h>
41 #include <sensor_msgs/LaserScan.h>
43 #include <std_msgs/String.h>
45 #include <boost/date_time/posix_time/posix_time.hpp>
46 #include <boost/lexical_cast.hpp>
65 MyRosBag(std::string path_, std::string image_topic_, std::string info_topic_, std::string laser_topic_)
67 image_topic(image_topic_),
68 info_topic(info_topic_),
69 laser_topic(laser_topic_)
71 global = ros::Time::now();
72 start = ros::Time::now();
73 ref = ros::Time::now();
75 boost::posix_time::ptime t(boost::posix_time::second_clock::local_time());
76 boost::gregorian::date d = t.date();
77 std::string date = to_iso_extended_string(d);
79 boost::posix_time::time_duration time = t.time_of_day();
86 boost::format hours(
"%02f");
89 boost::format minutes(
"%02f");
90 minutes % time.minutes();
92 boost::format seconds(
"%02f");
93 seconds % time.seconds();
95 std::string path = path_ +
"_" + date +
"-" + hours.str() +
"-" + minutes.str() +
"-" + seconds.str() +
".bag";
96 bag.open(path, rosbag::bagmode::Write);
102 std::cout<<__FUNCTION__<<std::endl;
104 std::cout<<__FUNCTION__<<std::endl;
121 ref = ref + (ros::Time::now() - start);
127 start = ros::Time::now();
137 ros::Time warped_time = ref + (ros::Time::now() - start);
144 bag.write(image_topic, warped_time, msg);
149 ros::Time warped_time = ref + (ros::Time::now() - start);
156 bag.write(image_topic, warped_time, msg);
178 ros::Time warped_time = ref + (ros::Time::now() - start);
185 bag.write(info_topic, warped_time, cam_info_msg);
194 ros::Time warped_time = ref + (ros::Time::now() - start);
201 bag.write(laser_topic, warped_time, laser_msg);
213 int main(
int argc,
char** argv)
215 ros::init(argc, argv,
"bag");
217 ros::NodeHandle nh(
"~");
220 nh.param<std::string>(
"bag_path",path,
"");
222 std::string image_topic;
223 nh.param<std::string>(
"image_topic",image_topic,
" ");
225 std::string info_topic;
226 nh.param<std::string>(
"info_topic",info_topic,
" ");
228 std::string laser_topic;
229 nh.param<std::string>(
"laser_topic",laser_topic,
" ");
231 MyRosBag my_bag(path, image_topic, info_topic, laser_topic);
235 cv::Mat image(320, 240, CV_8UC3, cv::Scalar(0,0,0));
236 cv::Mat image_clone = image.clone();
237 cv::putText(image_clone, std::string(
"Paused"), cv::Point (image.cols/2 - 50 , image.rows/2 - 10), cv::FONT_HERSHEY_SIMPLEX, 0.8, cv::Scalar(0,255,0), 2, 8);
245 if ((ros::Time::now() - begin).toSec() >= 2 & record)
248 image_clone = image.clone();
249 cv::putText(image_clone, std::string(
"Paused"), cv::Point (image.cols/2 - 50 , image.rows/2 - 10), cv::FONT_HERSHEY_SIMPLEX, 0.8, cv::Scalar(0,255,0), 2, 8);
253 key = cv::waitKey(2);
257 image_clone = image.clone();
260 cv::putText(image_clone, std::string(
"Paused"), cv::Point (image.cols/2 - 50 , image.rows/2 - 10), cv::FONT_HERSHEY_SIMPLEX, 0.8, cv::Scalar(0,255,0), 2, 8);
264 cv::putText(image_clone, std::string(
"Recording"), cv::Point (image.cols/2 - 60 , image.rows/2 - 10), cv::FONT_HERSHEY_SIMPLEX, 0.8, cv::Scalar(0,255,0), 2, 8);
266 begin = ros::Time::now();
271 cv::imshow(
"Display window", image_clone);
void LaserScanHandler(const sensor_msgs::LaserScan &laser_msg)
void writeImage(const sensor_msgs::ImagePtr &msg)
ros::Subscriber laser_sub
int main(int argc, char **argv)
void CameraInfoHandler(const sensor_msgs::CameraInfo &cam_info_msg)
void compressedImageHandler(const sensor_msgs::CompressedImagePtr msg)
MyRosBag(std::string path_, std::string image_topic_, std::string info_topic_, std::string laser_topic_)
void writeImage(const sensor_msgs::CompressedImagePtr &msg)
ros::Subscriber image_sub