35 #include <opencv2/highgui/highgui.hpp> 38 #include <sensor_msgs/Image.h> 42 #include <boost/thread.hpp> 43 #include <boost/format.hpp> 62 CvVideoWriter* video_writer;
67 : filename_format_(
""), count_(0), _time(
ros::Time::now().toSec())
72 std::string format_string;
73 local_nh.
param(
"filename_format", format_string, std::string(
"frame%04i.jpg"));
74 filename_format_.parse(format_string);
76 local_nh.
param(
"sec_per_frame", sec_per_frame_, 0.1);
85 ROS_INFO(
"Initialized sec per frame to %f", sec_per_frame_);
92 void image_cb(
const sensor_msgs::ImageConstPtr& msg)
94 boost::lock_guard<boost::mutex> guard(image_mutex_);
101 if (msg->encoding.find(
"bayer") != std::string::npos)
102 boost::const_pointer_cast<sensor_msgs::Image>(msg)->encoding =
"mono8";
110 ROS_ERROR(
"Unable to convert %s image to bgr8", msg->encoding.c_str());
114 if(delay >= sec_per_frame_)
118 if (!image.empty()) {
123 std::string file_extension = filename.substr(filename.length() - 4, 4);
124 if (filename.length() >= 4 && file_extension ==
".raw")
126 std::ofstream raw_file;
127 raw_file.open(filename.c_str());
128 if (raw_file.is_open() ==
false)
134 raw_file.write((
char*)(msg->data.data()), msg->data.size());
140 if (cv::imwrite(filename, image) ==
false)
148 video_writer = cvCreateVideoWriter(
"video.avi", CV_FOURCC(
'M',
'J',
'P',
'G'),
149 int(1.0/sec_per_frame_), cvSize(image->width, image->height));
152 cvWriteFrame(video_writer, image);
155 ROS_INFO(
"Saved image %s", filename.c_str());
158 ROS_WARN(
"Couldn't save image, no data!");
164 int main(
int argc,
char **argv)
169 ROS_WARN(
"extract_images: image has not been remapped! Typical command-line usage:\n" 170 "\t$ ./extract_images image:=<image topic> [transport]");
CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
std::string resolveName(const std::string &name, bool remap=true) const
#define ROS_WARN_STREAM(args)