31
31
#include < boost/format.hpp>
32
32
33
33
#include < sensor_msgs/Image.h>
34
+ #include < sensor_msgs/CompressedImage.h>
34
35
#include < sensor_msgs/CameraInfo.h>
35
36
36
37
#include < image_proc/processor.h>
39
40
#include < opencv2/highgui/highgui.hpp> // for cv::imwrite
40
41
41
42
#include " bag_tools/image_bag_processor.h"
42
-
43
+ # include < iostream >
43
44
/* *
44
45
* Saves color images from raw input
45
46
*/
@@ -60,22 +61,33 @@ class ImageSaver
60
61
std::cerr << " ERROR Processing image" << std::endl;
61
62
return ;
62
63
}
63
- std::string filename =
64
- boost::str (boost::format (" %s/%s%lu.%s" )
65
- % save_dir_
66
- % prefix_
67
- % img->header .stamp .toNSec ()
68
- % filetype_);
69
- if (!cv::imwrite (filename, output.color ))
70
- ROS_ERROR_STREAM (" ERROR Saving " << filename);
71
- else
72
- {
73
- ROS_DEBUG_STREAM (" Saved " << filename);
74
- num_saved_++;
75
- }
64
+ save_image (img->header .stamp .toNSec (), output.color );
65
+ }
66
+ void save_compressed (const sensor_msgs::CompressedImageConstPtr& _compressed)
67
+ {
68
+ cv::Mat image_uncomrpessed = cv::imdecode (cv::Mat (_compressed->data ),1 );
69
+ save_image (_compressed->header .stamp .toNSec (), image_uncomrpessed);
76
70
}
77
71
78
72
private:
73
+ void save_image (uint64_t _time_stamp, const cv::Mat& _image)
74
+ {
75
+ std::string filename =
76
+ boost::str (boost::format (" %s/%s%lu.%s" )
77
+ % save_dir_
78
+ % prefix_
79
+ % _time_stamp
80
+ % filetype_);
81
+ if (!cv::imwrite (filename, _image))
82
+ {
83
+ ROS_ERROR_STREAM (" ERROR Saving " << filename);
84
+ }
85
+ else
86
+ {
87
+ ROS_DEBUG_STREAM (" Saved " << filename);
88
+ num_saved_++;
89
+ }
90
+ }
79
91
80
92
image_proc::Processor processor_;
81
93
std::string save_dir_;
@@ -104,6 +116,7 @@ int main(int argc, char** argv)
104
116
ImageSaver saver (out_dir, filetype, prefix);
105
117
bag_tools::ImageBagProcessor processor (image_topic);
106
118
processor.registerCallback (boost::bind (&ImageSaver::save, saver, _1));
119
+ processor.registerCompressedCallback (boost::bind (&ImageSaver::save_compressed, saver, _1));
107
120
108
121
for (int i = 4 ; i < argc; ++i)
109
122
processor.processBag (argv[i]);
0 commit comments