converter-csv.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_CSV_H
5 #define __RS_CONVERTER_CONVERTER_CSV_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_csv : public converter_base {
18  protected:
21 
22  public:
24  : _filePath(filePath)
25  , _streamType(streamType)
26  {
27  }
28 
29  std::string name() const override
30  {
31  return "CSV converter";
32  }
33 
34  void convert(rs2::frame& frame) override
35  {
36  auto depthframe = frame.as<rs2::depth_frame>();
37 
38  if (!depthframe || !(_streamType == rs2_stream::RS2_STREAM_ANY || depthframe.get_profile().stream_type() == _streamType)) {
39  return;
40  }
41 
42  if (frames_map_get_and_set(depthframe.get_profile().stream_type(), depthframe.get_frame_number())) {
43  return;
44  }
45 
47  [this, &frame] {
48  auto depthframe = frame.as<rs2::depth_frame>();
49 
50  std::stringstream filename;
51  filename << _filePath
52  << "_" << depthframe.get_profile().stream_name()
53  << "_" << std::setprecision(14) << std::fixed << depthframe.get_timestamp()
54  << ".csv";
55 
56  std::stringstream metadata_file;
57  metadata_file << _filePath
58  << "_" << depthframe.get_profile().stream_name()
59  << "_metadata_" << std::setprecision(14) << std::fixed << depthframe.get_timestamp()
60  << ".txt";
61 
62  std::string filenameS = filename.str();
63  std::string metadataS = metadata_file.str();
64 
66  [filenameS, metadataS, depthframe] {
67  std::ofstream fs(filenameS, std::ios::trunc);
68 
69  if (fs) {
70  for (int y = 0; y < depthframe.get_height(); y++) {
71  auto delim = "";
72 
73  for (int x = 0; x < depthframe.get_width(); x++) {
74  fs << delim << depthframe.get_distance(x, y);
75  delim = ",";
76  }
77 
78  fs << '\n';
79  }
80 
81  fs.flush();
82  }
83 
84  metadata_to_txtfile(depthframe, metadataS);
85  });
86 
88  });
89  }
90  };
91 
92  }
93  }
94 }
95 
96 
97 #endif
GLint y
std::string name() const override
Definition: cah-model.h:10
GLsizei const GLchar *const * string
void convert(rs2::frame &frame) override
GLdouble x
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
void metadata_to_txtfile(const rs2::frame &frm, const std::string &filename)
Definition: converter.hpp:20
bool frames_map_get_and_set(rs2_stream streamType, frame_number_t frameNumber)
Definition: converter.hpp:51
converter_csv(const std::string &filePath, rs2_stream streamType=rs2_stream::RS2_STREAM_ANY)
T as() const
Definition: rs_frame.hpp:580


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:12