Skip to content

Commit 806cccb

Browse files
committed
Merge pull request #1 from abarobopec/indigo-devel
Indigo devel
2 parents 390b719 + a3da4cf commit 806cccb

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

bag_tools/include/bag_tools/image_bag_processor.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <boost/progress.hpp>
3535

3636
#include <sensor_msgs/Image.h>
37+
#include <sensor_msgs/CompressedImage.h>
3738

3839
namespace bag_tools
3940
{
@@ -44,6 +45,7 @@ class ImageBagProcessor
4445
public:
4546

4647
typedef boost::function<void (const sensor_msgs::ImageConstPtr&)> CallbackType;
48+
typedef boost::function<void (const sensor_msgs::CompressedImageConstPtr&)> CallbackCompressedType;
4749

4850
ImageBagProcessor(const std::string& image_topic) :
4951
image_topic_(image_topic)
@@ -56,6 +58,11 @@ class ImageBagProcessor
5658
callback_ = callback;
5759
}
5860

61+
void registerCompressedCallback(const CallbackCompressedType& callback)
62+
{
63+
callback_compressed_ = callback;
64+
}
65+
5966
/**
6067
* Processes given bagfile, calls registered callback function when
6168
* a message is found.
@@ -81,8 +88,17 @@ class ImageBagProcessor
8188
if (m.getTopic() == image_topic_)
8289
{
8390
sensor_msgs::Image::ConstPtr img_msg = m.instantiate<sensor_msgs::Image>();
84-
if (img_msg != NULL)
91+
if (img_msg != NULL && callback_.empty() == false)
92+
{
8593
callback_(img_msg);
94+
}else
95+
{
96+
sensor_msgs::CompressedImageConstPtr compressed = m.instantiate<sensor_msgs::CompressedImage>();
97+
if(compressed != NULL && callback_compressed_.empty() == false)
98+
{
99+
callback_compressed_(compressed);
100+
}
101+
}
86102
}
87103
++show_progress;
88104
}
@@ -94,6 +110,7 @@ class ImageBagProcessor
94110

95111
std::string image_topic_;
96112
CallbackType callback_;
113+
CallbackCompressedType callback_compressed_;
97114

98115
};
99116

bag_tools/scripts/bag_tools/cut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def cut(inbags, outbagfile, start, duration):
5353
outbag = rosbag.Bag(outbagfile, 'w')
5454
num_messages = 0
5555
for inbag in inbags:
56-
rospy.loginfo(' Extracting messages from:', inbag
56+
rospy.loginfo(' Extracting messages from:', inbag)
5757
for topic, msg, t in rosbag.Bag(inbag,'r').read_messages(start_time=start_time, end_time=end_time):
5858
outbag.write(topic, msg, t)
5959
num_messages = num_messages + 1

bag_tools/scripts/bag_tools/make_video.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
PKG = 'bag_tools' # this package name
3434

3535
import roslib; roslib.load_manifest(PKG)
36-
36+
import rospy
3737
import tempfile
3838
import subprocess
3939
import glob
@@ -56,7 +56,7 @@ def create_video(tmp_dir, args):
5656
i = i + 1
5757

5858
rospy.loginfo('Creating video...')
59-
cmd = ["ffmpeg", "-f", "image2", "-r", str(args.fps), "-i", tmp_dir + "/img-%d.jpg", "-sameq", args.output]
59+
cmd = ["ffmpeg", "-f", "image2", "-r", str(args.fps), "-i", tmp_dir + "/img-%d.jpg", args.output]
6060
rospy.loginfo(' {}'.format(' '.join(cmd)))
6161
subprocess.call(cmd)
6262

bag_tools/src/extract_images.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <boost/format.hpp>
3232

3333
#include <sensor_msgs/Image.h>
34+
#include <sensor_msgs/CompressedImage.h>
3435
#include <sensor_msgs/CameraInfo.h>
3536

3637
#include <image_proc/processor.h>
@@ -39,7 +40,7 @@
3940
#include <opencv2/highgui/highgui.hpp> // for cv::imwrite
4041

4142
#include "bag_tools/image_bag_processor.h"
42-
43+
#include <iostream>
4344
/**
4445
* Saves color images from raw input
4546
*/
@@ -60,22 +61,33 @@ class ImageSaver
6061
std::cerr << "ERROR Processing image" << std::endl;
6162
return;
6263
}
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);
7670
}
7771

7872
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+
}
7991

8092
image_proc::Processor processor_;
8193
std::string save_dir_;
@@ -104,6 +116,7 @@ int main(int argc, char** argv)
104116
ImageSaver saver(out_dir, filetype, prefix);
105117
bag_tools::ImageBagProcessor processor(image_topic);
106118
processor.registerCallback(boost::bind(&ImageSaver::save, saver, _1));
119+
processor.registerCompressedCallback(boost::bind(&ImageSaver::save_compressed, saver, _1));
107120

108121
for (int i = 4; i < argc; ++i)
109122
processor.processBag(argv[i]);

0 commit comments

Comments
 (0)