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 
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;
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
rs2::video_frame::get_stride_in_bytes
int get_stride_in_bytes() const
Definition: rs_frame.hpp:685
stbi_write_png
STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes)
rs2::frame
Definition: rs_frame.hpp:345
rs2::colorizer
Definition: rs_processing.hpp:752
rs2::tools::converter::converter_png
Definition: converter-png.hpp:19
string
GLsizei const GLchar *const * string
Definition: glad/glad/glad.h:2861
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_png::_filePath
std::string _filePath
Definition: converter-png.hpp:21
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::tools::converter::converter_png::name
std::string name() const override
Definition: converter-png.hpp:31
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_STREAM_DEPTH
@ RS2_STREAM_DEPTH
Definition: rs_sensor.h:46
rs2::video_frame::get_width
int get_width() const
Definition: rs_frame.hpp:661
rs2::tools::converter::converter_png::converter_png
converter_png(const std::string &filePath, rs2_stream streamType=rs2_stream::RS2_STREAM_ANY)
Definition: converter-png.hpp:25
rs2::tools::converter::converter_base
Definition: converter.hpp:25
RS2_STREAM_ANY
@ RS2_STREAM_ANY
Definition: rs_sensor.h:45
rs2::tools::converter::converter_png::_colorizer
rs2::colorizer _colorizer
Definition: converter-png.hpp:22
tools
Definition: lrs-device-controller.h:26
test-projection-from-recording.filename
filename
Definition: test-projection-from-recording.py:15
rs2::tools::converter::converter_png::_streamType
rs2_stream _streamType
Definition: converter-png.hpp:20
rs2::tools::converter::metadata_to_txtfile
void metadata_to_txtfile(const rs2::frame &frm, const std::string &filename)
Definition: converter.cpp:9
rs2::tools::converter::converter_png::convert
void convert(rs2::frame &frame) override
Definition: converter-png.hpp:36
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
rs2::video_frame::get_bytes_per_pixel
int get_bytes_per_pixel() const
Definition: rs_frame.hpp:709
rs2::tools::converter::frame_number_t
unsigned long long frame_number_t
Definition: converter.hpp:23
rs2_stream
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:43
rs2::video_frame::get_height
int get_height() const
Definition: rs_frame.hpp:673
rs2::filter::process
rs2::frame process(rs2::frame frame) const override
Definition: rs_processing.hpp:370


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