cpp-alignimages.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 <sstream>
00008 #include <iostream>
00009 #include <iomanip>
00010 #include <thread>
00011 
00012 texture_buffer buffers[6];
00013 
00014 #pragma pack(push, 1)
00015 struct rgb_pixel
00016 {
00017     uint8_t r,g,b; 
00018 };
00019 #pragma pack(pop)
00020 
00021 int main(int argc, char * argv[]) try
00022 {
00023     rs::log_to_console(rs::log_severity::warn);
00024     //rs::log_to_file(rs::log_severity::debug, "librealsense.log");
00025 
00026     rs::context ctx;
00027     if(ctx.get_device_count() == 0) throw std::runtime_error("No device detected. Is it plugged in?");
00028     rs::device & dev = *ctx.get_device(0);
00029 
00030     dev.enable_stream(rs::stream::depth, rs::preset::best_quality);
00031     dev.enable_stream(rs::stream::color, rs::preset::best_quality);
00032     try { dev.enable_stream(rs::stream::infrared2, rs::preset::best_quality); } catch(...) {}
00033     dev.start();
00034 
00035     // Open a GLFW window
00036     glfwInit();
00037     std::ostringstream ss; ss << "CPP Image Alignment Example (" << dev.get_name() << ")";
00038     GLFWwindow * win = glfwCreateWindow(dev.is_stream_enabled(rs::stream::infrared2) ? 1920 : 1280, 960, ss.str().c_str(), 0, 0);
00039     glfwMakeContextCurrent(win);
00040 
00041     while (!glfwWindowShouldClose(win))
00042     {
00043         // Wait for new images
00044         glfwPollEvents();
00045         dev.wait_for_frames();
00046 
00047         // Clear the framebuffer
00048         int w,h;
00049         glfwGetFramebufferSize(win, &w, &h);
00050         glViewport(0, 0, w, h);
00051         glClear(GL_COLOR_BUFFER_BIT);
00052 
00053         // Draw the images        
00054         glPushMatrix();
00055         glfwGetWindowSize(win, &w, &h);
00056         glOrtho(0, w, h, 0, -1, +1);
00057         int s = w / (dev.is_stream_enabled(rs::stream::infrared2) ? 3 : 2);
00058         buffers[0].show(dev, rs::stream::color, 0, 0, s, h-h/2);
00059         buffers[1].show(dev, rs::stream::color_aligned_to_depth, s, 0, s, h-h/2);
00060         buffers[2].show(dev, rs::stream::depth_aligned_to_color, 0, h/2, s, h-h/2);
00061         buffers[3].show(dev, rs::stream::depth, s, h/2, s, h-h/2);
00062         if(dev.is_stream_enabled(rs::stream::infrared2))
00063         {
00064             buffers[4].show(dev, rs::stream::infrared2_aligned_to_depth, 2*s, 0, s, h-h/2);
00065             buffers[5].show(dev, rs::stream::depth_aligned_to_infrared2, 2*s, h/2, s, h-h/2);
00066         }
00067         glPopMatrix();
00068         glfwSwapBuffers(win);
00069     }
00070 
00071     glfwDestroyWindow(win);
00072     glfwTerminate();
00073     return EXIT_SUCCESS;
00074 }
00075 catch(const rs::error & e)
00076 {
00077     std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
00078     return EXIT_FAILURE;
00079 }
00080 catch(const std::exception & e)
00081 {
00082     std::cerr << e.what() << std::endl;
00083     return EXIT_FAILURE;
00084 }


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