forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-utils.hpp
74 lines (71 loc) · 2.53 KB
/
example-utils.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2021 Intel Corporation. All Rights Reserved.
#pragma once
#include <iostream>
#include <string>
#include <map>
#include <librealsense2/rs.hpp>
#include <algorithm>
//////////////////////////////
// Demos Helpers //
//////////////////////////////
// Find devices with specified streams
bool device_with_streams(std::vector <rs2_stream> stream_requests, std::string& out_serial)
{
rs2::context ctx;
auto devs = ctx.query_devices();
std::vector <rs2_stream> unavailable_streams = stream_requests;
for (auto dev : devs)
{
std::map<rs2_stream, bool> found_streams;
for (auto& type : stream_requests)
{
found_streams[type] = false;
for (auto& sensor : dev.query_sensors())
{
for (auto& profile : sensor.get_stream_profiles())
{
if (profile.stream_type() == type)
{
found_streams[type] = true;
unavailable_streams.erase(std::remove(unavailable_streams.begin(), unavailable_streams.end(), type), unavailable_streams.end());
if (dev.supports(RS2_CAMERA_INFO_SERIAL_NUMBER))
out_serial = dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
}
}
}
}
// Check if all streams are found in current device
bool found_all_streams = true;
for (auto& stream : found_streams)
{
if (!stream.second)
{
found_all_streams = false;
break;
}
}
if (found_all_streams)
return true;
}
// After scanning all devices, not all requested streams were found
for (auto& type : unavailable_streams)
{
switch (type)
{
case RS2_STREAM_POSE:
case RS2_STREAM_FISHEYE:
std::cerr << "Connect T26X and rerun the demo" << std::endl;
break;
case RS2_STREAM_DEPTH:
std::cerr << "The demo requires Realsense camera with DEPTH sensor" << std::endl;
break;
case RS2_STREAM_COLOR:
std::cerr << "The demo requires Realsense camera with RGB sensor" << std::endl;
break;
default:
throw std::runtime_error("The requested stream: " + std::to_string(type) + ", for the demo is not supported by connected devices!"); // stream type
}
}
return false;
}