35 #include <opencv2/highgui/highgui.hpp> 38 #include <sensor_msgs/Image.h> 42 #include <boost/thread.hpp> 43 #include <boost/format.hpp> 60 CvVideoWriter* video_writer;
65 : filename_format_(
""), count_(0), _time(
ros::Time::now().toSec())
70 std::string format_string;
71 local_nh.
param(
"filename_format", format_string, std::string(
"frame%04i.jpg"));
72 filename_format_.parse(format_string);
74 local_nh.
param(
"sec_per_frame", sec_per_frame_, 0.1);
83 ROS_INFO(
"Initialized sec per frame to %f", sec_per_frame_);
90 void image_cb(
const sensor_msgs::ImageConstPtr& msg)
92 boost::lock_guard<boost::mutex> guard(image_mutex_);
99 if (msg->encoding.find(
"bayer") != std::string::npos)
100 boost::const_pointer_cast<sensor_msgs::Image>(msg)->encoding =
"mono8";
108 ROS_ERROR(
"Unable to convert %s image to bgr8", msg->encoding.c_str());
112 if(delay >= sec_per_frame_)
116 if (!image.empty()) {
120 cv::imwrite(filename, image);
124 video_writer = cvCreateVideoWriter(
"video.avi", CV_FOURCC(
'M',
'J',
'P',
'G'),
125 int(1.0/sec_per_frame_), cvSize(image->width, image->height));
128 cvWriteFrame(video_writer, image);
131 ROS_INFO(
"Saved image %s", filename.c_str());
134 ROS_WARN(
"Couldn't save image, no data!");
140 int main(
int argc,
char **argv)
145 ROS_WARN(
"extract_images: image has not been remapped! Typical command-line usage:\n" 146 "\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())
std::string resolveName(const std::string &name, bool remap=true) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const