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 {
20 
21  public:
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;
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
rs2::video_frame::get_stride_in_bytes
int get_stride_in_bytes() const
Definition: rs_frame.hpp:685
rs2::frame
Definition: rs_frame.hpp:345
rs2::tools::converter::converter_raw::_streamType
rs2_stream _streamType
Definition: converter-raw.hpp:18
rs2::tools::converter::converter_raw::name
std::string name() const override
Definition: converter-raw.hpp:28
rs2::frame::get_frame_number
unsigned long long get_frame_number() const
Definition: rs_frame.hpp:523
string
GLsizei const GLchar *const * string
Definition: glad/glad/glad.h:2861
rs2::tools::converter::converter_raw::converter_raw
converter_raw(const std::string &filePath, rs2_stream streamType=rs2_stream::RS2_STREAM_ANY)
Definition: converter-raw.hpp:22
rs2::stream_profile::stream_name
std::string stream_name() const
Definition: rs_frame.hpp:113
rs2::stream_profile::stream_type
rs2_stream stream_type() const
Definition: rs_frame.hpp:39
rs2::frame::get_data
const void * get_data() const
Definition: rs_frame.hpp:547
rs2::tools::converter::converter_base::wait_sub_workers
void wait_sub_workers()
Definition: converter.cpp:47
rs2::tools::converter::converter_base::add_sub_worker
void add_sub_worker(const F &f)
Definition: converter.hpp:40
rs2::frame::get_timestamp
double get_timestamp() const
Definition: rs_frame.hpp:476
rs2
Definition: animated.h:9
rs2::tools::converter::converter_base::frames_map_get_and_set
bool frames_map_get_and_set(rs2_stream streamType, frame_number_t frameNumber)
Definition: converter.cpp:31
rs2::tools::converter::converter_base
Definition: converter.hpp:25
RS2_STREAM_ANY
@ RS2_STREAM_ANY
Definition: rs_sensor.h:45
rs2::tools::converter::converter_raw::convert
void convert(rs2::frame &frame) override
Definition: converter-raw.hpp:33
tools
Definition: lrs-device-controller.h:26
test-projection-from-recording.filename
filename
Definition: test-projection-from-recording.py:15
rs2::tools::converter::converter_raw::_filePath
std::string _filePath
Definition: converter-raw.hpp:19
rs2::tools::converter::metadata_to_txtfile
void metadata_to_txtfile(const rs2::frame &frm, const std::string &filename)
Definition: converter.cpp:9
rs2::frame::as
T as() const
Definition: rs_frame.hpp:582
rs2::tools::converter::converter_base::start_worker
void start_worker(const F &f)
Definition: converter.hpp:35
rs2::frame::get_profile
stream_profile get_profile() const
Definition: rs_frame.hpp:559
rs2::video_frame
Definition: rs_frame.hpp:638
test-ts-same-fps.fs
fs
Definition: test-ts-same-fps.py:57
rs2_stream
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:43
rs2::configurations::ply::binary
@ binary
Definition: device-model.h:174
rs2::video_frame::get_height
int get_height() const
Definition: rs_frame.hpp:673
rs2::tools::converter::converter_raw
Definition: converter-raw.hpp:17


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Fri Aug 2 2024 08:30:01