Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
examples
multicam
rs-multicam.cpp
Go to the documentation of this file.
1
// License: Apache 2.0. See LICENSE file in root directory.
2
// Copyright(c) 2015-2017 Intel Corporation. All Rights Reserved.
3
4
#include <
librealsense2/rs.hpp
>
// Include RealSense Cross Platform API
5
#include "
example.hpp
"
// Include short list of convenience functions for rendering
6
7
#include <map>
8
#include <vector>
9
10
int
main
(
int
argc,
char
* argv[])
try
11
{
12
// Create a simple OpenGL window for rendering:
13
window
app(1280, 960,
"CPP Multi-Camera Example"
);
14
15
rs2::context
ctx
;
// Create librealsense context for managing devices
16
17
std::map<std::string, rs2::colorizer> colorizers;
// Declare map from device serial number to colorizer (utility class to convert depth data RGB colorspace)
18
19
std::vector<rs2::pipeline>
pipelines
;
20
21
// Capture serial numbers before opening streaming
22
std::vector<std::string> serials;
23
for
(
auto
&&
dev
: ctx.
query_devices
())
24
serials.push_back(
dev
.get_info(
RS2_CAMERA_INFO_SERIAL_NUMBER
));
25
26
// Start a streaming pipe per each connected device
27
for
(
auto
&& serial : serials)
28
{
29
rs2::pipeline
pipe
(ctx);
30
rs2::config
cfg
;
31
cfg.
enable_device
(serial);
32
pipe.
start
(cfg);
33
pipelines.emplace_back(pipe);
34
// Map from each device's serial number to a different colorizer
35
colorizers[serial] =
rs2::colorizer
();
36
}
37
38
// We'll keep track of the last frame of each stream available to make the presentation persistent
39
std::map<int, rs2::frame> render_frames;
40
41
// Main app loop
42
while
(app)
43
{
44
// Collect the new frames from all the connected devices
45
std::vector<rs2::frame> new_frames;
46
for
(
auto
&&
pipe
: pipelines)
47
{
48
rs2::frameset
fs;
49
if
(
pipe
.poll_for_frames(&fs))
50
{
51
for
(
const
rs2::frame
&
f
: fs)
52
new_frames.emplace_back(
f
);
53
}
54
}
55
56
// Convert the newly-arrived frames to render-friendly format
57
for
(
const
auto
& frame : new_frames)
58
{
59
// Get the serial number of the current frame's device
60
auto
serial =
rs2::sensor_from_frame
(frame)->get_info(
RS2_CAMERA_INFO_SERIAL_NUMBER
);
61
// Apply the colorizer of the matching device and store the colorized frame
62
render_frames[frame.get_profile().unique_id()] = colorizers[serial].process(frame);
63
}
64
65
// Present all the collected frames with openGl mosaic
66
app.
show
(render_frames);
67
}
68
69
return
EXIT_SUCCESS;
70
}
71
catch
(
const
rs2::error
&
e
)
72
{
73
std::cerr
<<
"RealSense error calling "
<< e.
get_failed_function
() <<
"("
<< e.
get_failed_args
() <<
"):\n "
<< e.what() << std::endl;
74
return
EXIT_FAILURE;
75
}
76
catch
(
const
std::exception & e)
77
{
78
std::cerr
<< e.what() << std::endl;
79
return
EXIT_FAILURE;
80
}
rs2::error
Definition:
rs_types.hpp:92
export_ply_example.pipe
pipe
Definition:
export_ply_example.py:18
rs2::config
Definition:
rs_pipeline.hpp:124
rs2::frame
Definition:
rs_frame.hpp:343
test-bad-conditions.dev
dev
Definition:
test-bad-conditions.py:16
RS2_CAMERA_INFO_SERIAL_NUMBER
Definition:
rs_sensor.h:24
rs2::context::query_devices
device_list query_devices() const
Definition:
rs_context.hpp:112
rs2::frameset
Definition:
rs_frame.hpp:943
example.hpp
rs.hpp
rs2::config::enable_device
void enable_device(const std::string &serial)
Definition:
rs_pipeline.hpp:234
test-got-playback-frames.ctx
ctx
Definition:
test-got-playback-frames.py:165
rmse.e
e
Definition:
rmse.py:177
rs2::context
Definition:
rs_context.hpp:96
rs2::error::get_failed_args
const std::string & get_failed_args() const
Definition:
rs_types.hpp:117
f
GLdouble f
Definition:
glad/glad/glad.h:1518
test-got-playback-frames.cfg
cfg
Definition:
test-got-playback-frames.py:115
export_ply_example.colorizer
colorizer
Definition:
export_ply_example.py:28
window::show
void show(rs2::frame frame)
Definition:
example.hpp:652
main
int main(int argc, char *argv[])
Definition:
rs-multicam.cpp:10
rs2::pipeline
Definition:
rs_pipeline.hpp:362
window
Definition:
example.hpp:498
Catch::cerr
std::ostream & cerr()
rs2::pipeline::start
pipeline_profile start()
Definition:
rs_pipeline.hpp:392
pipelines
const GLuint * pipelines
Definition:
glext.h:1893
rs2::sensor_from_frame
std::shared_ptr< sensor > sensor_from_frame(frame f)
Definition:
rs_sensor.hpp:357
rs2::error::get_failed_function
const std::string & get_failed_function() const
Definition:
rs_types.hpp:112
librealsense2
Author(s): Sergey Dorodnicov
, Doron Hirshberg
, Mark Horn
, Reagan Lopez
, Itay Carpis
autogenerated on Mon May 3 2021 02:47:40