cpp-multicam.cpp
Go to the documentation of this file.
00001 // License: Apache 2.0. See LICENSE file in root directory.
00002 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
00003 
00004 #include <librealsense/rs.hpp>
00005 #include "example.hpp"
00006 
00007 #include <iostream>
00008 #include <algorithm>
00009 
00010 std::vector<texture_buffer> buffers;
00011 
00012 int main(int argc, char * argv[]) try
00013 {
00014     rs::log_to_console(rs::log_severity::warn);
00015     //rs::log_to_file(rs::log_severity::debug, "librealsense.log");
00016 
00017     rs::context ctx;
00018     if(ctx.get_device_count() == 0) throw std::runtime_error("No device detected. Is it plugged in?");
00019     
00020     // Enumerate all devices
00021     std::vector<rs::device *> devices;
00022     for(int i=0; i<ctx.get_device_count(); ++i)
00023     {
00024         devices.push_back(ctx.get_device(i));
00025     }
00026 
00027     // Configure and start our devices
00028     for(auto dev : devices)
00029     {
00030         std::cout << "Starting " << dev->get_name() << "... ";
00031         dev->enable_stream(rs::stream::depth, rs::preset::best_quality);
00032         dev->enable_stream(rs::stream::color, rs::preset::best_quality);
00033         dev->start();
00034         std::cout << "done." << std::endl;
00035     }
00036 
00037     // Depth and color
00038     buffers.resize(ctx.get_device_count() * 2);
00039 
00040     // Open a GLFW window
00041     glfwInit();
00042     std::ostringstream ss; ss << "CPP Multi-Camera Example";
00043     GLFWwindow * win = glfwCreateWindow(1280, 960, ss.str().c_str(), 0, 0);
00044     glfwMakeContextCurrent(win);
00045 
00046     int windowWidth, windowHeight;
00047     glfwGetWindowSize(win, &windowWidth, &windowHeight);
00048 
00049     // Does not account for correct aspect ratios
00050     auto perTextureWidth = int(windowWidth / devices.size());
00051     auto perTextureHeight = 480;
00052 
00053     while (!glfwWindowShouldClose(win))
00054     {
00055         // Wait for new images
00056         glfwPollEvents();
00057         
00058         // Draw the images
00059         int w,h;
00060         glfwGetFramebufferSize(win, &w, &h);
00061         glViewport(0, 0, w, h);
00062         glClear(GL_COLOR_BUFFER_BIT);
00063         
00064         glfwGetWindowSize(win, &w, &h);
00065         glPushMatrix();
00066         glOrtho(0, w, h, 0, -1, +1);
00067         glPixelZoom(1, -1);
00068         int i=0, x=0;
00069         for(auto dev : devices)
00070         {
00071             dev->poll_for_frames();
00072             const auto c = dev->get_stream_intrinsics(rs::stream::color), d = dev->get_stream_intrinsics(rs::stream::depth);
00073             buffers[i++].show(*dev, rs::stream::color, x, 0, perTextureWidth, perTextureHeight);
00074             buffers[i++].show(*dev, rs::stream::depth, x, perTextureHeight, perTextureWidth, perTextureHeight);
00075             x += perTextureWidth;
00076         }
00077 
00078         glPopMatrix();
00079         glfwSwapBuffers(win);
00080     }
00081 
00082     glfwDestroyWindow(win);
00083     glfwTerminate();
00084     return EXIT_SUCCESS;
00085 }
00086 catch(const rs::error & e)
00087 {
00088     std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
00089     return EXIT_FAILURE;
00090 }
00091 catch(const std::exception & e)
00092 {
00093     std::cerr << e.what() << std::endl;
00094     return EXIT_FAILURE;
00095 }


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Tue Jun 25 2019 19:54:38