converter-png.hpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2018 Intel Corporation. All Rights Reserved.
3 
4 #ifndef __RS_CONVERTER_CONVERTER_PNG_H
5 #define __RS_CONVERTER_CONVERTER_PNG_H
6 
7 
8 // 3rd party header for writing png files
9 #define STB_IMAGE_WRITE_IMPLEMENTATION
10 #include "stb_image_write.h"
11 
12 #include "../converter.hpp"
13 
14 
15 namespace rs2 {
16  namespace tools {
17  namespace converter {
18 
19  class converter_png : public converter_base {
21  std::string _filePath;
23 
24  public:
25  converter_png(const std::string& filePath, rs2_stream streamType = rs2_stream::RS2_STREAM_ANY)
26  : _filePath(filePath)
27  , _streamType(streamType)
28  {
29  }
30 
31  std::string name() const override
32  {
33  return "PNG converter";
34  }
35 
36  void convert(rs2::frame& frame) override
37  {
38  rs2::video_frame videoframe = frame.as<rs2::video_frame>();
39  if (!videoframe || !(_streamType == rs2_stream::RS2_STREAM_ANY || videoframe.get_profile().stream_type() == _streamType)) {
40  return;
41  }
42 
44  static_cast<rs2::tools::converter::frame_number_t>(videoframe.get_timestamp()))) {
45  return;
46  }
47 
49  [this, &frame] {
50  rs2::video_frame videoframe = frame.as<rs2::video_frame>();
51 
53  videoframe = _colorizer.process(videoframe);
54  }
55 
56  std::stringstream filename;
57  filename << _filePath
58  << "_" << videoframe.get_profile().stream_name()
59  << "_" << std::setprecision(14) << std::fixed << videoframe.get_timestamp()
60  << ".png";
61 
62  std::stringstream metadata_file;
63  metadata_file << _filePath
64  << "_" << videoframe.get_profile().stream_name()
65  << "_metadata_" << std::setprecision(14) << std::fixed << videoframe.get_timestamp()
66  << ".txt";
67 
68  std::string filenameS = filename.str();
69  std::string metadataS = metadata_file.str();
70 
72  [filenameS, metadataS, videoframe] {
74  filenameS.c_str()
75  , videoframe.get_width()
76  , videoframe.get_height()
77  , videoframe.get_bytes_per_pixel()
78  , videoframe.get_data()
79  , videoframe.get_stride_in_bytes()
80  );
81 
82  metadata_to_txtfile(videoframe, metadataS);
83  });
84 
86  });
87  }
88  };
89 
90  }
91  }
92 }
93 
94 
95 #endif
int get_bytes_per_pixel() const
Definition: rs_frame.hpp:709
void convert(rs2::frame &frame) override
std::string stream_name() const
Definition: rs_frame.hpp:113
Definition: animated.h:9
double get_timestamp() const
Definition: rs_frame.hpp:476
std::string name() const override
rs2::frame process(rs2::frame frame) const override
bool frames_map_get_and_set(rs2_stream streamType, frame_number_t frameNumber)
Definition: converter.cpp:31
T as() const
Definition: rs_frame.hpp:582
converter_png(const std::string &filePath, rs2_stream streamType=rs2_stream::RS2_STREAM_ANY)
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
int get_height() const
Definition: rs_frame.hpp:673
void metadata_to_txtfile(const rs2::frame &frm, const std::string &filename)
Definition: converter.cpp:9
int get_width() const
Definition: rs_frame.hpp:661
const void * get_data() const
Definition: rs_frame.hpp:547
STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes)
int get_stride_in_bytes() const
Definition: rs_frame.hpp:685
rs2_stream stream_type() const
Definition: rs_frame.hpp:39
unsigned long long frame_number_t
Definition: converter.hpp:23
stream_profile get_profile() const
Definition: rs_frame.hpp:559


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Thu Dec 22 2022 03:43:16