internal-tests-uv-map.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include "catch.h"
5 #include <cmath>
6 #include <iostream>
7 #include <chrono>
8 #include <ctime>
9 #include <algorithm>
10 #include <librealsense2/rs.hpp>
12 #include "../../common/tiny-profiler.h"
13 #include "./../unit-tests-common.h"
14 #include "./../src/environment.h"
15 
16 using namespace librealsense;
17 using namespace librealsense::platform;
18 
19 std::vector<device_profiles> uv_tests_configurations = {
20  //D465
21  { { { RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 1280, 1024, 0 },{ RS2_STREAM_COLOR, RS2_FORMAT_YUYV, 2000, 1500, 0 } }, 30, true },
22  { { { RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 1280, 720, 0 },{ RS2_STREAM_COLOR, RS2_FORMAT_YUYV, 2000, 1500, 0 } }, 30, true },
23  { { { RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 960, 768, 0 },{ RS2_STREAM_COLOR, RS2_FORMAT_YUYV, 2000, 1500, 0 } }, 30, true },
24  { { { RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 1280, 1024, 0 },{ RS2_STREAM_COLOR, RS2_FORMAT_YUYV, 1920, 1080, 0 } }, 30, true },
25  { { { RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 1280, 720, 0 },{ RS2_STREAM_COLOR, RS2_FORMAT_YUYV, 1920, 1080, 0 } }, 30, true },
26  { { { RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 960, 768, 0 },{ RS2_STREAM_COLOR, RS2_FORMAT_YUYV, 1920, 1080, 0 } }, 30, true },
27  { { { RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 1280, 1024, 0 },{ RS2_STREAM_COLOR, RS2_FORMAT_YUYV, 960, 720, 0 } }, 30, true },
28  { { { RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 1280, 720, 0 },{ RS2_STREAM_COLOR, RS2_FORMAT_YUYV, 960, 720, 0 } }, 30, true },
29  { { { RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 960, 768, 0 },{ RS2_STREAM_COLOR, RS2_FORMAT_YUYV, 960, 720, 0 } }, 30, true },
30  //L500
31  //{ { { RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 1024, 768, 0 },{ RS2_STREAM_INFRARED, RS2_FORMAT_Y8, 1024, 768, 0 },{ RS2_STREAM_COLOR, RS2_FORMAT_YUYV, 1920, 1080, 0 } }, 30, true },
32 };
33 
34 TEST_CASE("Generate UV-MAP", "[live]")
35 {
37 
38  // Require at least one device to be plugged in
40  auto list = ctx.query_devices();
41  REQUIRE(list.size());
42 
43  for (auto&& test_cfg : uv_tests_configurations)
44  {
45  // Record Depth + RGB streams
46  {
47  // We want the points object to be persistent so we can display the last cloud when a frame drops
49 
51  // Declare RealSense pipeline, encapsulating the actual device and sensors
53 
55  for (auto&& pf: test_cfg.streams)
56  cfg.enable_stream(pf.stream, pf.index, pf.width, pf.height, pf.format, pf.fps);
57 
58  // Start streaming with default recommended configuration
59  auto pf = cfg.resolve(pipe);
60  for (auto&& snr : pf.get_device().query_sensors())
61  {
62  if (snr.supports(RS2_OPTION_GLOBAL_TIME_ENABLED))
63  snr.set_option(RS2_OPTION_GLOBAL_TIME_ENABLED, false);
64 
65  if (snr.supports(RS2_OPTION_EMITTER_ENABLED))
66  {
67  snr.set_option(RS2_OPTION_EMITTER_ENABLED, false);
68  std::this_thread::sleep_for(std::chrono::milliseconds(100));
69  snr.set_option(RS2_OPTION_EMITTER_ENABLED, true);
70  std::this_thread::sleep_for(std::chrono::milliseconds(100));
71  snr.set_option(RS2_OPTION_LASER_POWER, 60.f);
72  }
73  }
74 
75  rs2::temporal_filter temp_filter; // Temporal - reduces temporal noise
76  const std::string disparity_filter_name = "Disparity";
77  rs2::disparity_transform depth_to_disparity(true);
78  rs2::disparity_transform disparity_to_depth(false);
79  std::vector<rs2::filter> filters;
80 
81  // The following order of emplacement will dictate the orders in which filters are applied
82  filters.push_back(std::move(depth_to_disparity));
83  filters.push_back(std::move(temp_filter));
84  filters.push_back(std::move(disparity_to_depth));
85 
86  // Start streaming with default recommended configuration
87  pf = pipe.start(cfg);
88 
89  size_t i = 0;
90  size_t startup = 50;
91 
92  while (i < startup + 200)
93  {
94  // Wait for the next set of frames from the camera
95  auto frames = pipe.wait_for_frames();
96  if (++i < startup)
97  continue;
98 
99  auto depth = frames.get_depth_frame();
100  auto color = frames.get_color_frame();
101  // For D465 streaming of Depth + IR + RGB at 4K is not possible.
102  // Therefore the data collection will be performed in two iterations
103  //auto ir = frames.get_infrared_frame(1);
104 
105  // Prerequisite is that the required three streams are available and that the depth/ir are aligned
106  if (!(color && depth /*&& ir && (depth.get_frame_number() == ir.get_frame_number())*/))
107  return;
108 
109  // Using of the temporal filter shall be recommended
111  //for (auto&& filter : filters)
112  // depth = filter.process(depth);
113 
114  pc.map_to(color);
115  // Generate the pointcloud and texture mappings
116  points = pc.process(depth);
117 
118  auto pf = color.get_profile().as<rs2::video_stream_profile>();
119  auto w = pf.width();
120  auto h = pf.height();
121  std::stringstream ss;
122  ss << "_yuyv_" << w << "_" << h;
123  std::string rgb_res(ss.str().c_str());
124 
125  ss.clear(); ss.str(""); ss << i - startup << "_yuyv_" << w << "_" << h << ".bin";
126  {
127  assert(color.get_data_size() == w * h * sizeof(uint16_t));
128  std::ofstream outfile(ss.str().c_str(), std::ios::binary);
129  outfile.write((const char*)color.get_data(), color.get_data_size());
130  }
131 
132  pf = depth.get_profile().as<rs2::video_stream_profile>();
133  w = pf.width();
134  h = pf.height();
135 
136  auto tex_ptr = (float2*)points.get_texture_coordinates();
137  auto vert_ptr = (rs2::vertex*)points.get_vertices();
138  auto uv_map = reinterpret_cast<const char*>(tex_ptr);
139 
140  std::cout << "Frame size is " << w * h << std::endl;
141 
142  ss.clear(); ss.str(""); ss << i - startup << "_uv" << w << "_" << h << rgb_res <<".bin";
143  {
144  std::ofstream outfile(ss.str().c_str(), std::ios::binary);
145  outfile.write(uv_map, w * h * sizeof(float2));
146  }
147 
148  pf = depth.get_profile().as<rs2::video_stream_profile>();
149  w = pf.width();
150  h = pf.height();
151  ss.clear(); ss.str(""); ss << i - startup << "_depth_" << w << "_" << h << rgb_res << ".bin";
152  {
153  REQUIRE(depth.get_data_size() == w * h * sizeof(uint16_t));
154  std::ofstream outfile(ss.str().c_str(), std::ios::binary);
155  outfile.write((const char*)depth.get_data(), depth.get_data_size());
156  }
157 
158  //pf = ir.get_profile().as<rs2::video_stream_profile>();
159  //w = pf.width();
160  //h = pf.height();
161  //ss.clear(); ss.str(""); ss << i - startup << "_ir_" << w << "_" << h << ".bin";
162  //{
163  // assert(ir.get_data_size() == w * h * sizeof(uint8_t));
164  // std::ofstream outfile(ss.str().c_str(), std::ios::binary);
165  // outfile.write((const char*)ir.get_data(), ir.get_data_size());
166  //}
167 
168  std::cout << "Iteration " << i - startup << " files were written" << std::endl;
169  }
170  }
171 
172  // record IR stream separately
173  if (true)
174  {
177 
178  auto fmt = test_cfg.streams[0]; // Depth and IR align
180 
181  // Start streaming with default recommended configuration
182  auto pf = cfg.resolve(pipe);
183  for (auto&& snr : pf.get_device().query_sensors())
184  {
185  if (snr.supports(RS2_OPTION_EMITTER_ENABLED))
186  snr.set_option(RS2_OPTION_EMITTER_ENABLED, false);
187  }
188 
189  // Start streaming with default recommended configuration
190  pf = pipe.start(cfg);
191 
192  size_t i = 0;
193  size_t startup = 30;
194 
195  while (i < startup)
196  {
197  // Wait for the next set of frames from the camera
198  auto frames = pipe.wait_for_frames();
199  if (++i < startup)
200  continue;
201 
202  auto ir_frame = frames.get_infrared_frame(1);
203 
204  // Prerequisite is that the required three streams are available and that the depth/ir are aligned
205  if (!ir_frame)
206  return;
207 
208  auto pf = ir_frame.get_profile().as<rs2::video_stream_profile>();
209  auto w = pf.width();
210  auto h = pf.height();
211  std::stringstream ss;
212  ss << i - startup << "_ir_" << w << "_" << h << ".bin";
213  {
214  assert(ir_frame.get_data_size() == w * h * sizeof(uint16_t));
215  std::ofstream outfile(ss.str().c_str(), std::ios::binary);
216  outfile.write((const char*)ir_frame.get_data(), ir_frame.get_data_size());
217  }
218 
219  std::cout << "Iteration " << i - startup << " files were written" << std::endl;
220  }
221  }
222  }
223 }
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
GLuint color
stream_profile get_profile() const
Definition: rs_frame.hpp:557
device_list query_devices() const
Definition: rs_context.hpp:112
std::vector< device_profiles > uv_tests_configurations
GLint GLint GLsizei GLsizei GLsizei depth
unsigned short uint16_t
Definition: stdint.h:79
void map_to(frame mapped)
GLdouble GLdouble GLdouble w
GLsizei const GLchar *const * string
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1960
const texture_coordinate * get_texture_coordinates() const
Definition: rs_frame.hpp:792
GLdouble f
rs2::frame process(rs2::frame frame) const override
std::ostream & cout()
REQUIRE(n_callbacks==1)
const vertex * get_vertices() const
Definition: rs_frame.hpp:767
TEST_CASE("Generate UV-MAP","[live]")
void enable_stream(rs2_stream stream_type, int stream_index, int width, int height, rs2_format format=RS2_FORMAT_ANY, int framerate=0)
pipeline_profile resolve(std::shared_ptr< rs2_pipeline > p) const
const GLuint GLenum const void * binary
Definition: glext.h:1882
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
int i
void log_to_console(rs2_log_severity min_severity)
Definition: log.cpp:44
pipeline_profile start()
GLdouble GLdouble GLint GLint const GLdouble * points


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