2 #include <ros/console.h>
3 #include <ros/duration.h>
5 #include <ros/master.h>
6 #include <ros/node_handle.h>
8 #include <ros/subscriber.h>
12 #include <sensor_msgs/Image.h>
15 #include <cv_bridge/cv_bridge.h>
16 #include <sensor_msgs/image_encodings.h>
19 #include <opencv2/highgui/highgui.hpp>
21 #include <opencv2/imgproc/imgproc.hpp>
30 cv_bridge::CvImagePtr img_ptr;
34 img_ptr = cv_bridge::toCvCopy(rgb_image_msg, sensor_msgs::image_encodings::BGR8);
35 }
catch (cv_bridge::Exception& e) {
36 ROS_ERROR(
"Could not deserialize rgb image: %s", e.what());
45 int main(
int argc,
char **argv) {
46 ros::init(argc, argv,
"rgbd_transport_server");
49 ros::NodeHandle nh_private(
"~");
52 nh_private.getParam(
"rate", rate);
55 nh_private.getParam(
"filename", filename);
58 nh_private.getParam(
"format", format);
61 nh_private.getParam(
"size", size);
63 if (format.size() != 4)
65 ROS_ERROR(
"Parameter 'format' should be string of size 4 (e.g., MJPG, DIVX, MPG4, etc)");
73 cv::VideoWriter video_writer;
74 bool initialized =
false;
77 cv::Size2i video_size;
79 ros::WallTime last_master_check = ros::WallTime::now();
85 if (ros::WallTime::now() >= last_master_check + ros::WallDuration(1))
87 last_master_check = ros::WallTime::now();
88 if (!ros::master::check())
90 ROS_FATAL(
"Lost connection to master");
103 video_size = cv::Size2i(
static_cast<int>(size *
rgb_image.cols),
104 static_cast<int>(size *
rgb_image.rows));
105 video_writer.open(filename.
c_str(), cv::VideoWriter::fourcc(format[0], format[1], format[2], format[3]), rate, video_size);
107 if (!video_writer.isOpened())
124 cv::Mat rgb_image_scaled;
125 cv::resize(
rgb_image, rgb_image_scaled, video_size);
128 video_writer.write(rgb_image_scaled);
136 video_writer.release();