converter-raw.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_RAW_H
5 #define __RS_CONVERTER_CONVERTER_RAW_H
6 
7 
8 #include <fstream>
9 
10 #include "../converter.hpp"
11 
12 
13 namespace rs2 {
14  namespace tools {
15  namespace converter {
16 
17  class converter_raw : public converter_base {
19  std::string _filePath;
20 
21  public:
22  converter_raw(const std::string& filePath, rs2_stream streamType = rs2_stream::RS2_STREAM_ANY)
23  : _filePath(filePath)
24  , _streamType(streamType)
25  {
26  }
27 
28  std::string name() const override
29  {
30  return "RAW converter";
31  }
32 
33  void convert(rs2::frame& frame) override
34  {
35  rs2::video_frame videoframe = frame.as<rs2::video_frame>();
36 
37  if (!videoframe || !(_streamType == rs2_stream::RS2_STREAM_ANY || videoframe.get_profile().stream_type() == _streamType)) {
38  return;
39  }
40 
41  if (frames_map_get_and_set(videoframe.get_profile().stream_type(), videoframe.get_frame_number())) {
42  return;
43  }
44 
46  [this, &frame] {
47  rs2::video_frame videoframe = frame.as<rs2::video_frame>();
48 
49  std::stringstream filename;
50  filename << _filePath
51  << "_" << videoframe.get_profile().stream_name()
52  << "_" << std::setprecision(14) << std::fixed << videoframe.get_timestamp()
53  << ".raw";
54 
55  std::stringstream metadata_file;
56  metadata_file << _filePath
57  << "_" << videoframe.get_profile().stream_name()
58  << "_metadata_" << std::setprecision(14) << std::fixed << videoframe.get_timestamp()
59  << ".txt";
60 
61  std::string filenameS = filename.str();
62  std::string metadataS = metadata_file.str();
63 
65  [filenameS, metadataS, videoframe] {
66  std::ofstream fs(filenameS, std::ios::binary | std::ios::trunc);
67 
68  if (fs) {
69  fs.write(
70  static_cast<const char *>(videoframe.get_data())
71  , videoframe.get_stride_in_bytes() * videoframe.get_height());
72 
73  fs.flush();
74  }
75 
76  metadata_to_txtfile(videoframe, metadataS);
77  });
78 
80  });
81  }
82  };
83 
84  }
85  }
86 }
87 
88 
89 #endif
std::string name() const override
std::string stream_name() const
Definition: rs_frame.hpp:113
Definition: animated.h:9
double get_timestamp() const
Definition: rs_frame.hpp:476
converter_raw(const std::string &filePath, rs2_stream streamType=rs2_stream::RS2_STREAM_ANY)
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
void convert(rs2::frame &frame) override
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
unsigned long long get_frame_number() const
Definition: rs_frame.hpp:523
void metadata_to_txtfile(const rs2::frame &frm, const std::string &filename)
Definition: converter.cpp:9
const void * get_data() const
Definition: rs_frame.hpp:547
int get_stride_in_bytes() const
Definition: rs_frame.hpp:685
rs2_stream stream_type() const
Definition: rs_frame.hpp:39
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