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 {
23 
24  public:
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 
43  if (frames_map_get_and_set(videoframe.get_profile().stream_type(), videoframe.get_timestamp())) {
44  return;
45  }
46 
48  [this, &frame] {
49  rs2::video_frame videoframe = frame.as<rs2::video_frame>();
50 
52  videoframe = _colorizer.process(videoframe);
53  }
54 
55  std::stringstream filename;
56  filename << _filePath
57  << "_" << videoframe.get_profile().stream_name()
58  << "_" << std::setprecision(14) << std::fixed << videoframe.get_timestamp()
59  << ".png";
60 
61  std::stringstream metadata_file;
62  metadata_file << _filePath
63  << "_" << videoframe.get_profile().stream_name()
64  << "_metadata_" << std::setprecision(14) << std::fixed << videoframe.get_timestamp()
65  << ".txt";
66 
67  std::string filenameS = filename.str();
68  std::string metadataS = metadata_file.str();
69 
71  [filenameS, metadataS, videoframe] {
73  filenameS.c_str()
74  , videoframe.get_width()
75  , videoframe.get_height()
76  , videoframe.get_bytes_per_pixel()
77  , videoframe.get_data()
78  , videoframe.get_stride_in_bytes()
79  );
80 
81  metadata_to_txtfile(videoframe, metadataS);
82  });
83 
85  });
86  }
87  };
88 
89  }
90  }
91 }
92 
93 
94 #endif
void convert(rs2::frame &frame) override
stream_profile get_profile() const
Definition: rs_frame.hpp:557
int get_bytes_per_pixel() const
Definition: rs_frame.hpp:707
const void * get_data() const
Definition: rs_frame.hpp:545
Definition: cah-model.h:10
std::string stream_name() const
Definition: rs_frame.hpp:113
GLsizei const GLchar *const * string
std::string name() const override
rs2::frame process(rs2::frame frame) const override
double get_timestamp() const
Definition: rs_frame.hpp:474
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
void metadata_to_txtfile(const rs2::frame &frm, const std::string &filename)
Definition: converter.hpp:20
STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes)
bool frames_map_get_and_set(rs2_stream streamType, frame_number_t frameNumber)
Definition: converter.hpp:51
int get_height() const
Definition: rs_frame.hpp:671
int get_stride_in_bytes() const
Definition: rs_frame.hpp:683
rs2_stream stream_type() const
Definition: rs_frame.hpp:39
int get_width() const
Definition: rs_frame.hpp:659
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