test-hdr.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2021 Intel Corporation. All Rights Reserved.
3 
5 // This set of tests is valid for any device that supports the HDR feature //
7 
8 //#cmake:add-file ../unit-tests-common.h
9 //#cmake:add-file ../approx.h
10 
11 #define CATCH_CONFIG_MAIN
12 #include "../catch.h"
13 #include "../unit-tests-common.h"
14 
15 #include <easylogging++.h>
16 #ifdef BUILD_SHARED_LIBS
17 // With static linkage, ELPP is initialized by librealsense, so doing it here will
18 // create errors. When we're using the shared .so/.dll, the two are separate and we have
19 // to initialize ours if we want to use the APIs!
21 #endif
22 
23 using namespace rs2;
24 
25 // HDR CONFIGURATION TESTS
26 TEST_CASE("HDR Config - default config", "[hdr][live]")
27 {
29  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
30  {
31  rs2::device_list devices_list = ctx.query_devices();
32  size_t device_count = devices_list.size();
33  if (devices_list.size() != 0)
34  {
36 
37  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
38  {
39  auto exposure_range = depth_sensor.get_option_range(RS2_OPTION_EXPOSURE);
40  auto gain_range = depth_sensor.get_option_range(RS2_OPTION_GAIN);
41 
42  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 1);
43  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
44 
45  depth_sensor.set_option(RS2_OPTION_SEQUENCE_ID, 1);
46  REQUIRE(depth_sensor.get_option(RS2_OPTION_SEQUENCE_ID) == 1.f);
47  auto exp = depth_sensor.get_option(RS2_OPTION_EXPOSURE);
48  REQUIRE(depth_sensor.get_option(RS2_OPTION_EXPOSURE) == exposure_range.def - 1000); //w/a
49  REQUIRE(depth_sensor.get_option(RS2_OPTION_GAIN) == gain_range.def);
50 
51  depth_sensor.set_option(RS2_OPTION_SEQUENCE_ID, 2);
52  REQUIRE(depth_sensor.get_option(RS2_OPTION_SEQUENCE_ID) == 2.f);
53  REQUIRE(depth_sensor.get_option(RS2_OPTION_EXPOSURE) == exposure_range.min);
54  REQUIRE(depth_sensor.get_option(RS2_OPTION_GAIN) == gain_range.min);
55 
56  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 0);
57  auto enabled = depth_sensor.get_option(RS2_OPTION_HDR_ENABLED);
58  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 0.f);
59  }
60  }
61  else
62  {
63  std::cout << "No device was found - skipping test" << std::endl;
64  }
65  }
66 }
67 
68 TEST_CASE("HDR Config - custom config", "[hdr][live]")
69 {
70  // Require at least one device to be plugged in
72  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
73  {
74  rs2::device_list devices_list = ctx.query_devices();
75  size_t device_count = devices_list.size();
76  if (devices_list.size() != 0)
77  {
79 
80  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
81  {
82  depth_sensor.set_option(RS2_OPTION_SEQUENCE_SIZE, 2);
83  REQUIRE(depth_sensor.get_option(RS2_OPTION_SEQUENCE_SIZE) == 2.f);
84 
85  depth_sensor.set_option(RS2_OPTION_SEQUENCE_ID, 1);
86  REQUIRE(depth_sensor.get_option(RS2_OPTION_SEQUENCE_ID) == 1.f);
87  depth_sensor.set_option(RS2_OPTION_EXPOSURE, 120.f);
88  REQUIRE(depth_sensor.get_option(RS2_OPTION_EXPOSURE) == 120.f);
89  depth_sensor.set_option(RS2_OPTION_GAIN, 90.f);
90  REQUIRE(depth_sensor.get_option(RS2_OPTION_GAIN) == 90.f);
91 
92 
93  depth_sensor.set_option(RS2_OPTION_SEQUENCE_ID, 2);
94  REQUIRE(depth_sensor.get_option(RS2_OPTION_SEQUENCE_ID) == 2.f);
95  depth_sensor.set_option(RS2_OPTION_EXPOSURE, 1200.f);
96  REQUIRE(depth_sensor.get_option(RS2_OPTION_EXPOSURE) == 1200.f);
97  depth_sensor.set_option(RS2_OPTION_GAIN, 20.f);
98  REQUIRE(depth_sensor.get_option(RS2_OPTION_GAIN) == 20.f);
99 
100  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 1);
101  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
102 
103  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 0);
104  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 0.f);
105  }
106  }
107  else
108  {
109  std::cout << "No device was found - skipping test" << std::endl;
110  }
111  }
112 }
113 
114 // HDR STREAMING TESTS
115 TEST_CASE("HDR Streaming - default config", "[hdr][live][using_pipeline]")
116 {
118  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
119  {
120  rs2::device_list devices_list = ctx.query_devices();
121  size_t device_count = devices_list.size();
122  if (devices_list.size() != 0)
123  {
125 
126  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
127  {
128  auto exposure_range = depth_sensor.get_option_range(RS2_OPTION_EXPOSURE);
129  auto gain_range = depth_sensor.get_option_range(RS2_OPTION_GAIN);
130 
131  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 1);
132  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
133 
135  cfg.enable_stream(RS2_STREAM_DEPTH);
136  cfg.enable_stream(RS2_STREAM_INFRARED, 1);
138  pipe.start(cfg);
139 
140  int iteration = 0;
141  while (++iteration < 100)
142  {
144  REQUIRE_NOTHROW(data = pipe.wait_for_frames());
145  rs2::depth_frame out_depth_frame = data.get_depth_frame();
146 
147  if (iteration < 3)
148  continue;
149 
150  if (out_depth_frame.supports_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID))
151  {
152  long long frame_exposure = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE);
153  long long frame_gain = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_GAIN_LEVEL);
154  auto seq_id = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID);
155 
156  if (seq_id == 0)
157  {
158  REQUIRE(frame_exposure == exposure_range.def - 1000.f); // w/a
159  REQUIRE(frame_gain == gain_range.def);
160  }
161  else
162  {
163  REQUIRE(frame_exposure == exposure_range.min);
164  REQUIRE(frame_gain == gain_range.min);
165  }
166  }
167  }
168  }
169  }
170  else
171  {
172  std::cout << "No device was found - skipping test" << std::endl;
173  }
174  }
175 }
176 
177 TEST_CASE("HDR Streaming - custom config", "[hdr][live][using_pipeline]")
178 {
180  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
181  {
182  rs2::device_list devices_list = ctx.query_devices();
183  size_t device_count = devices_list.size();
184  if (devices_list.size() != 0)
185  {
187 
188  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
189  {
190  depth_sensor.set_option(RS2_OPTION_SEQUENCE_SIZE, 2);
191  REQUIRE(depth_sensor.get_option(RS2_OPTION_SEQUENCE_SIZE) == 2.f);
192 
193  auto first_exposure = 120.f;
194  auto first_gain = 90.f;
195  depth_sensor.set_option(RS2_OPTION_SEQUENCE_ID, 1);
196  REQUIRE(depth_sensor.get_option(RS2_OPTION_SEQUENCE_ID) == 1.f);
197  depth_sensor.set_option(RS2_OPTION_EXPOSURE, first_exposure);
198  REQUIRE(depth_sensor.get_option(RS2_OPTION_EXPOSURE) == first_exposure);
199  depth_sensor.set_option(RS2_OPTION_GAIN, first_gain);
200  REQUIRE(depth_sensor.get_option(RS2_OPTION_GAIN) == first_gain);
201 
202 
203  auto second_exposure = 1200.f;
204  auto second_gain = 20.f;
205  depth_sensor.set_option(RS2_OPTION_SEQUENCE_ID, 2);
206  REQUIRE(depth_sensor.get_option(RS2_OPTION_SEQUENCE_ID) == 2.f);
207  depth_sensor.set_option(RS2_OPTION_EXPOSURE, second_exposure);
208  REQUIRE(depth_sensor.get_option(RS2_OPTION_EXPOSURE) == second_exposure);
209  depth_sensor.set_option(RS2_OPTION_GAIN, second_gain);
210  REQUIRE(depth_sensor.get_option(RS2_OPTION_GAIN) == second_gain);
211 
212  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 1);
213  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
214 
216  cfg.enable_stream(RS2_STREAM_DEPTH);
217  cfg.enable_stream(RS2_STREAM_INFRARED, 1);
219  pipe.start(cfg);
220 
221  int iteration = 0;
222  while (++iteration < 100)
223  {
225  REQUIRE_NOTHROW(data = pipe.wait_for_frames());
226  rs2::depth_frame out_depth_frame = data.get_depth_frame();
227 
228  if (iteration < 3)
229  continue;
230 
231  if (out_depth_frame.supports_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID))
232  {
233  long long frame_exposure = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE);
234  long long frame_gain = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_GAIN_LEVEL);
235  auto seq_id = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID);
236 
237  if (seq_id == 0)
238  {
239  REQUIRE(frame_exposure == first_exposure);
240  REQUIRE(frame_gain == first_gain);
241  }
242  else
243  {
244  REQUIRE(frame_exposure == second_exposure);
245  REQUIRE(frame_gain == second_gain);
246  }
247  }
248  }
249  }
250  }
251  else
252  {
253  std::cout << "No device was found - skipping test" << std::endl;
254  }
255  }
256 }
257 
258 // HDR CHANGING CONFIG WHILE STREAMING TESTS
259 TEST_CASE("HDR Config while Streaming", "[hdr][live][using_pipeline]")
260 {
262  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
263  {
264  rs2::device_list devices_list = ctx.query_devices();
265  size_t device_count = devices_list.size();
266  if (devices_list.size() != 0)
267  {
269 
270  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
271  {
272  auto exposure_range = depth_sensor.get_option_range(RS2_OPTION_EXPOSURE);
273  auto gain_range = depth_sensor.get_option_range(RS2_OPTION_GAIN);
274 
275  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 1);
276  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
277 
279  cfg.enable_stream(RS2_STREAM_DEPTH);
280  cfg.enable_stream(RS2_STREAM_INFRARED, 1);
282  pipe.start(cfg);
283 
284  auto required_exposure = exposure_range.def - 1000; // w/a
285  auto required_gain = gain_range.def;
286  auto changed_exposure = 33000.f;
287  auto changed_gain = 150.f;
288 
289  int iteration = 0;
290  while (++iteration < 100)
291  {
293  REQUIRE_NOTHROW(data = pipe.wait_for_frames());
294  rs2::depth_frame out_depth_frame = data.get_depth_frame();
295 
296  if (iteration < 3 || (iteration > 30 && iteration < 36))
297  continue;
298 
299  if (iteration == 30)
300  {
301  depth_sensor.set_option(RS2_OPTION_SEQUENCE_ID, 1);
302  REQUIRE(depth_sensor.get_option(RS2_OPTION_SEQUENCE_ID) == 1.f);
303  depth_sensor.set_option(RS2_OPTION_EXPOSURE, changed_exposure);
304  REQUIRE(depth_sensor.get_option(RS2_OPTION_EXPOSURE) == changed_exposure);
305  depth_sensor.set_option(RS2_OPTION_GAIN, changed_gain);
306  REQUIRE(depth_sensor.get_option(RS2_OPTION_GAIN) == changed_gain);
307  required_exposure = changed_exposure;
308  required_gain = changed_gain;
309  continue;
310  }
311 
312  if (out_depth_frame.supports_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID))
313  {
314  long long frame_exposure = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE);
315  long long frame_gain = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_GAIN_LEVEL);
316  auto seq_id = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID);
317 
318 
319  if (seq_id == 0)
320  {
321  REQUIRE(frame_exposure == required_exposure);
322  REQUIRE(frame_gain == required_gain);
323  }
324  else
325  {
326  REQUIRE(frame_exposure == exposure_range.min);
327  REQUIRE(frame_gain == gain_range.min);
328  }
329  }
330  }
331  }
332  }
333  else
334  {
335  std::cout << "No device was found - skipping test" << std::endl;
336  }
337  }
338 }
339 
340 // CHECKING HDR AFTER PIPE RESTART
341 TEST_CASE("HDR Running - restart hdr at restream", "[hdr][live][using_pipeline]")
342 {
344  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
345  {
346  rs2::device_list devices_list = ctx.query_devices();
347  size_t device_count = devices_list.size();
348  if (devices_list.size() != 0)
349  {
351 
352  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
353  {
357  pipe.start(cfg);
358 
359  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 1);
360  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
361 
362  for (int i = 0; i < 10; ++i)
363  {
365  REQUIRE_NOTHROW(data = pipe.wait_for_frames());
366  }
367  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
368  pipe.stop();
369 
370  pipe.start(cfg);
371  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
372  pipe.stop();
373  }
374  }
375  else
376  {
377  std::cout << "No device was found - skipping test" << std::endl;
378  }
379  }
380 }
381 
382 // CHECKING SEQUENCE ID WHILE STREAMING
383 TEST_CASE("HDR Streaming - checking sequence id", "[hdr][live][using_pipeline]")
384 {
386  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
387  {
388  rs2::device_list devices_list = ctx.query_devices();
389  size_t device_count = devices_list.size();
390  if (devices_list.size() != 0)
391  {
393 
394  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
395  {
400  pipe.start(cfg);
401 
402  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 1.f);
403  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
404 
405  int iteration = 0;
406  int sequence_id = -1;
407  int iterations_for_preparation = 6;
408  while (++iteration < 50) // Application still alive?
409  {
411  REQUIRE_NOTHROW(data = pipe.wait_for_frames());
412 
413  if (iteration < iterations_for_preparation)
414  continue;
415 
416  auto depth_frame = data.get_depth_frame();
418  {
420  auto ir_frame = data.get_infrared_frame(1);
421  auto ir_seq_id = ir_frame.get_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID);
422  if (iteration == iterations_for_preparation)
423  {
424  REQUIRE(depth_seq_id == ir_seq_id);
425  sequence_id = depth_seq_id;
426  }
427  else
428  {
429  sequence_id = (sequence_id == 0) ? 1 : 0;
430  REQUIRE(sequence_id == depth_seq_id);
431  REQUIRE(sequence_id == ir_seq_id);
432  }
433  }
434  }
435  pipe.stop();
436  }
437  }
438  else
439  {
440  std::cout << "No device was found - skipping test" << std::endl;
441  }
442  }
443 }
444 
445 TEST_CASE("Emitter on/off - checking sequence id", "[hdr][live][using_pipeline]")
446 {
448  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
449  {
450  rs2::device_list devices_list = ctx.query_devices();
451  size_t device_count = devices_list.size();
452  if (devices_list.size() != 0)
453  {
455 
456  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
457  {
462  pipe.start(cfg);
463 
464  depth_sensor.set_option(RS2_OPTION_EMITTER_ON_OFF, 1);
465  REQUIRE(depth_sensor.get_option(RS2_OPTION_EMITTER_ON_OFF) == 1.f);
466 
467  int iteration = 0;
468  int sequence_id = -1;
469  int iterations_for_preparation = 6;
470  while (++iteration < 50) // Application still alive?
471  {
473  REQUIRE_NOTHROW(data = pipe.wait_for_frames());
474 
475  if (iteration < iterations_for_preparation)
476  continue;
477 
478  auto depth_frame = data.get_depth_frame();
479 
481  {
483  auto ir_frame = data.get_infrared_frame(1);
484  auto ir_seq_id = ir_frame.get_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID);
485 
486  if (iteration == iterations_for_preparation)
487  {
488  REQUIRE(depth_seq_id == ir_seq_id);
489  sequence_id = depth_seq_id;
490  }
491  else
492  {
493  sequence_id = (sequence_id == 0) ? 1 : 0;
494  REQUIRE(sequence_id == depth_seq_id);
495  REQUIRE(sequence_id == ir_seq_id);
496  }
497  }
498  }
499  pipe.stop();
500  }
501  }
502  else
503  {
504  std::cout << "No device was found - skipping test" << std::endl;
505  }
506  }
507 }
508 
509 //This tests checks that the previously saved merged frame is discarded after a pipe restart
510 TEST_CASE("HDR Merge - discard merged frame", "[hdr][live][using_pipeline]") {
511 
513  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
514  {
515  rs2::device_list devices_list = ctx.query_devices();
516  size_t device_count = devices_list.size();
517  if (devices_list.size() != 0)
518  {
520 
521  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
522  {
523  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 1);
524  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
525 
527  cfg.enable_stream(RS2_STREAM_DEPTH);
529  pipe.start(cfg);
530 
531  // initializing the merging filter
532  rs2::hdr_merge merging_filter;
533 
534  int num_of_iterations_in_serie = 10;
535  int first_series_last_merged_ts = -1;
536  for (int i = 0; i < num_of_iterations_in_serie; ++i)
537  {
539  REQUIRE_NOTHROW(data = pipe.wait_for_frames());
540  rs2::depth_frame out_depth_frame = data.get_depth_frame();
541 
542  if (out_depth_frame.supports_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID))
543  {
544  // merging the frames from the different HDR sequence IDs
545  auto merged_frameset = merging_filter.process(data);
546  auto merged_depth_frame = merged_frameset.as<rs2::frameset>().get_depth_frame();
547 
548  long long frame_ts = merged_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP);
549 
550  if (i == (num_of_iterations_in_serie - 1))
551  first_series_last_merged_ts = frame_ts;
552  }
553  }
554  REQUIRE(first_series_last_merged_ts != -1);
555 
556  pipe.stop();
557 
558  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
559 
560  pipe.start(cfg);
561 
562  for (int i = 0; i < 10; ++i)
563  {
565  REQUIRE_NOTHROW(data = pipe.wait_for_frames());
566  rs2::depth_frame out_depth_frame = data.get_depth_frame();
567 
568  if (out_depth_frame.supports_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID))
569  {
570  // merging the frames from the different HDR sequence IDs
571  auto merged_frameset = merging_filter.process(data);
572  auto merged_depth_frame = merged_frameset.as<rs2::frameset>().get_depth_frame();
573 
574  long long frame_ts = merged_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP);
575  REQUIRE(frame_ts > first_series_last_merged_ts);
576  }
577  }
578  pipe.stop();
579  }
580  }
581  else
582  {
583  std::cout << "No device was found - skipping test" << std::endl;
584  }
585  }
586 }
587 
588 
589 TEST_CASE("HDR Start Stop - recover manual exposure and gain", "[HDR]")
590 {
592  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
593  {
594  rs2::device_list devices_list = ctx.query_devices();
595  size_t device_count = devices_list.size();
596  if (devices_list.size() != 0)
597  {
599 
600  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
601  {
602  float gain_before_hdr = 50.f;
603  depth_sensor.set_option(RS2_OPTION_GAIN, gain_before_hdr);
604  REQUIRE(depth_sensor.get_option(RS2_OPTION_GAIN) == gain_before_hdr);
605 
606  float exposure_before_hdr = 5000.f;
607  depth_sensor.set_option(RS2_OPTION_EXPOSURE, exposure_before_hdr);
608  REQUIRE(depth_sensor.get_option(RS2_OPTION_EXPOSURE) == exposure_before_hdr);
609 
610  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 1);
611  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
612 
614  cfg.enable_stream(RS2_STREAM_DEPTH);
616  pipe.start(cfg);
617 
618  int iteration = 0;
619  int iteration_for_disable = 50;
620  int iteration_to_check_after_disable = iteration_for_disable + 2;
621  while (++iteration < 70)
622  {
624  REQUIRE_NOTHROW(data = pipe.wait_for_frames());
625 
626  rs2::depth_frame out_depth_frame = data.get_depth_frame();
627 
628  if (out_depth_frame.supports_frame_metadata(RS2_FRAME_METADATA_SEQUENCE_ID))
629  {
630  long long frame_gain = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_GAIN_LEVEL);
631  long long frame_exposure = out_depth_frame.get_frame_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE);
632 
633  if (iteration > iteration_for_disable && iteration < iteration_to_check_after_disable)
634  continue;
635 
636  if (iteration == iteration_for_disable)
637  {
638  depth_sensor.set_option(RS2_OPTION_HDR_ENABLED, 0);
639  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 0.f);
640  }
641  else if (iteration >= iteration_to_check_after_disable)
642  {
643  REQUIRE(frame_gain == gain_before_hdr);
644  REQUIRE(frame_exposure == exposure_before_hdr);
645  }
646  }
647  }
648  }
649  }
650  else
651  {
652  std::cout << "No device was found - skipping test" << std::endl;
653  }
654  }
655 }
656 
657 // CONTROLS STABILITY WHILE HDR ACTIVE
658 TEST_CASE("HDR Active - set locked options", "[hdr][live]") {
660  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
661  {
662  rs2::device_list devices_list = ctx.query_devices();
663  size_t device_count = devices_list.size();
664  if (devices_list.size() != 0)
665  {
667 
668  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
669  {
670  //setting laser ON
672  auto laser_power_before_hdr = depth_sensor.get_option(RS2_OPTION_LASER_POWER);
673 
674  std::this_thread::sleep_for((std::chrono::milliseconds)(1500));
675 
677  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
678 
679  // the following calls should not be performed and should send a LOG_WARNING
681  REQUIRE(depth_sensor.get_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE) == 0.f);
682 
684  REQUIRE(depth_sensor.get_option(RS2_OPTION_EMITTER_ENABLED) == 1.f);
685 
687  REQUIRE(depth_sensor.get_option(RS2_OPTION_EMITTER_ON_OFF) == 0.f);
688 
689  REQUIRE_NOTHROW(depth_sensor.set_option(RS2_OPTION_LASER_POWER, laser_power_before_hdr - 30.f));
690  REQUIRE(depth_sensor.get_option(RS2_OPTION_LASER_POWER) == laser_power_before_hdr);
691  }
692  }
693  else
694  {
695  std::cout << "No device was found - skipping test" << std::endl;
696  }
697  }
698 }
699 
700 
701 TEST_CASE("HDR Streaming - set locked options", "[hdr][live][using_pipeline]") {
703  if (make_context(SECTION_FROM_TEST_NAME, &ctx, "2.39.0"))
704  {
705  rs2::device_list devices_list = ctx.query_devices();
706  size_t device_count = devices_list.size();
707  if (devices_list.size() != 0)
708  {
710 
711  if (depth_sensor && depth_sensor.supports(RS2_OPTION_HDR_ENABLED))
712  {
713  //setting laser ON
715  auto laser_power_before_hdr = depth_sensor.get_option(RS2_OPTION_LASER_POWER);
716 
717  std::this_thread::sleep_for((std::chrono::milliseconds)(1500));
718 
720  REQUIRE(depth_sensor.get_option(RS2_OPTION_HDR_ENABLED) == 1.f);
721 
723  cfg.enable_stream(RS2_STREAM_DEPTH);
725  pipe.start(cfg);
726 
727  int iteration = 0;
728  while (++iteration < 50)
729  {
731  REQUIRE_NOTHROW(data = pipe.wait_for_frames());
732 
733  if (iteration == 20)
734  {
735  // the following calls should not be performed and should send a LOG_WARNING
737  REQUIRE(depth_sensor.get_option(RS2_OPTION_ENABLE_AUTO_EXPOSURE) == 0.f);
738 
740  REQUIRE(depth_sensor.get_option(RS2_OPTION_EMITTER_ENABLED) == 1.f);
741 
743  REQUIRE(depth_sensor.get_option(RS2_OPTION_EMITTER_ON_OFF) == 0.f);
744 
745  REQUIRE_NOTHROW(depth_sensor.set_option(RS2_OPTION_LASER_POWER, laser_power_before_hdr - 30.f));
746  REQUIRE(depth_sensor.get_option(RS2_OPTION_LASER_POWER) == laser_power_before_hdr);
747  }
748  }
749  }
750  }
751  else
752  {
753  std::cout << "No device was found - skipping test" << std::endl;
754  }
755  }
756 }
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
rs2_metadata_type get_frame_metadata(rs2_frame_metadata_value frame_metadata) const
Definition: rs_frame.hpp:497
device_list query_devices() const
Definition: rs_context.hpp:112
uint32_t size() const
Definition: rs_device.hpp:711
bool supports_frame_metadata(rs2_frame_metadata_value frame_metadata) const
Definition: rs_frame.hpp:509
Definition: cah-model.h:10
depth_frame get_depth_frame() const
Definition: rs_frame.hpp:1006
GLdouble f
rs2::frame process(rs2::frame frame) const override
#define INITIALIZE_EASYLOGGINGPP
std::ostream & cout()
REQUIRE(n_callbacks==1)
#define SECTION_FROM_TEST_NAME
GLenum GLenum GLsizei const GLuint GLboolean enabled
rs2::depth_sensor restart_first_device_and_return_depth_sensor(const rs2::context &ctx, const rs2::device_list &devices_list)
bool supports(rs2_camera_info info) const
Definition: rs_sensor.hpp:125
void enable_stream(rs2_stream stream_type, int stream_index, int width, int height, rs2_format format=RS2_FORMAT_ANY, int framerate=0)
bool make_context(const char *id, rs2::context *ctx, std::string min_api_version="0.0.0")
TEST_CASE("HDR Config - default config","[hdr][live]")
Definition: test-hdr.cpp:26
REQUIRE_NOTHROW(rs2_log(RS2_LOG_SEVERITY_INFO,"Log message using rs2_log()", nullptr))
video_frame get_infrared_frame(const size_t index=0) const
Definition: rs_frame.hpp:1032
int i
option_range get_option_range(rs2_option option) const
Definition: rs_options.hpp:84
pipeline_profile start()
GLboolean * data
void set_option(rs2_option option, float value) const
Definition: rs_options.hpp:99
float get_option(rs2_option option) const
Definition: rs_options.hpp:72
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:50:11