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);
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 }
device_list query_devices() const
Definition: rs_context.hpp:112
void enable_device(const std::string &serial)
e
Definition: rmse.py:177
const std::string & get_failed_args() const
Definition: rs_types.hpp:117
GLdouble f
void show(rs2::frame frame)
Definition: example.hpp:652
int main(int argc, char *argv[])
Definition: rs-multicam.cpp:10
std::ostream & cerr()
pipeline_profile start()
const GLuint * pipelines
Definition: glext.h:1893
std::shared_ptr< sensor > sensor_from_frame(frame f)
Definition: rs_sensor.hpp:357
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