-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcpp-multicam.cpp
More file actions
98 lines (81 loc) · 2.79 KB
/
cpp-multicam.cpp
File metadata and controls
98 lines (81 loc) · 2.79 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2015 Intel Corporation. All Rights Reserved.
#include <librealsense/rs.hpp>
#include "example.hpp"
#include <iostream>
#include <algorithm>
std::vector<texture_buffer> buffers;
int main(int argc, char * argv[]) try
{
rs::log_to_console(rs::log_severity::warn);
//rs::log_to_file(rs::log_severity::debug, "librealsense.log");
rs::context ctx;
if (ctx.get_device_count() == 0) throw std::runtime_error("No device detected. Is it plugged in?");
// Enumerate all devices
std::vector<rs::device *> devices;
for (int i = 0; i<ctx.get_device_count(); ++i)
{
devices.push_back(ctx.get_device(i));
}
// Configure and start our devices
for (auto dev : devices)
{
std::cout << "Starting " << dev->get_name() << "... ";
dev->enable_stream(rs::stream::depth, rs::preset::best_quality);
// dev->enable_stream(rs::stream::color, rs::preset::best_quality);
dev->start();
std::cout << "done." << std::endl;
}
// Depth and color
//buffers.resize(ctx.get_device_count() * 2);
buffers.resize(ctx.get_device_count());
// Open a GLFW window
glfwInit();
std::ostringstream ss; ss << "CPP Multi-Camera Example";
GLFWwindow * win = glfwCreateWindow(1280, 480, ss.str().c_str(), 0, 0);
glfwMakeContextCurrent(win);
int windowWidth, windowHeight;
glfwGetWindowSize(win, &windowWidth, &windowHeight);
// Does not account for correct aspect ratios
auto perTextureWidth = windowWidth / devices.size();
auto perTextureHeight = 480;
while (!glfwWindowShouldClose(win))
{
// Wait for new images
glfwPollEvents();
// Draw the images
int w, h;
glfwGetFramebufferSize(win, &w, &h);
glViewport(0, 0, w, h);
glClear(GL_COLOR_BUFFER_BIT);
glfwGetWindowSize(win, &w, &h);
glPushMatrix();
glOrtho(0, w, h, 0, -1, +1);
glPixelZoom(1, -1);
int i = 0, x = 0;
for (auto dev : devices)
{
dev->poll_for_frames();
//const auto c = dev->get_stream_intrinsics(rs::stream::color), d = dev->get_stream_intrinsics(rs::stream::depth);
//buffers[i++].show(*dev, rs::stream::color, x, 0, perTextureWidth, perTextureHeight);
//buffers[i++].show(*dev, rs::stream::depth, x, perTextureHeight, perTextureWidth, perTextureHeight);
buffers[i++].show(*dev, rs::stream::depth, x, 0, perTextureWidth, perTextureHeight);
x += perTextureWidth;
}
glPopMatrix();
glfwSwapBuffers(win);
}
glfwDestroyWindow(win);
glfwTerminate();
return EXIT_SUCCESS;
}
catch (const rs::error & e)
{
std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
return EXIT_FAILURE;
}
catch (const std::exception & e)
{
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}