Intel Real Sense программирование о librealsense2 - PullRequest
0 голосов
/ 02 июля 2018

Я хочу получить 1280x720 изображение глубины и 1280x720 цветное изображение.

Итак, я основал как coded:

// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.

#include "librealsense2/rs.hpp" // Include RealSense Cross Platform API
#include "example.hpp"          // Include short list of convenience functions for rendering
#include "opencv2/opencv.hpp"
#include <iostream>
#include "stb-master\stb_image_write.h"


using namespace std;
using namespace cv;


// Capture Example demonstrates how to
// capture depth and color video streams and render them to the screen



int main(int argc, char * argv[]) try
{
    int width = 1280;
    int height = 720;
    rs2::log_to_console(RS2_LOG_SEVERITY_ERROR);
    // Create a simple OpenGL window for rendering:
    window app(width, height, "RealSense Capture Example");
    // Declare two textures on the GPU, one for color and one for depth
    texture depth_image, color_image;

    // Declare depth colorizer for pretty visualization of depth data
    rs2::colorizer color_map;
    color_map.set_option(RS2_OPTION_HISTOGRAM_EQUALIZATION_ENABLED,1.f);
    color_map.set_option(RS2_OPTION_COLOR_SCHEME, 2.f);

    // Declare RealSense pipeline, encapsulating the actual device and sensors
    rs2::pipeline pipe;
    // Start streaming with default recommended configuration

    pipe.start();

    while (app) // Application still alive?
    {
        rs2::frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camera

        rs2::frame depth = color_map(data.get_depth_frame()); // Find and colorize the depth data
        rs2::frame color = data.get_color_frame();            // Find the color data

                                                              // For cameras that don't have RGB sensor, we'll render infrared frames instead of color
        if (!color)
            color = data.get_infrared_frame();

        // Render depth on to the first half of the screen and color on to the second
        depth_image.render(depth, { 0,               0, app.width() / 2, app.height() });
        color_image.render(color, { app.width() / 2, 0, app.width() / 2, app.height() });
    }

    return EXIT_SUCCESS;
}
catch (const rs2::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;
}

Я хочу к этому ..

  1. Нажмите c <- значение клавиатуры </li>
  2. сохранить цветное изображение и изображение глубины в формате PNG

Я могу получить code о 2. но я не знаю, как вызвать действие, когда я нажимаю "c"

Полагаю, мне нужно использовать это example.hpp.

GLFWwindow * win = glfwCreateWindow(tile_w*cols, tile_h*rows, ss.str().c_str(), 0, 0);
glfwSetWindowUserPointer(win, &dev);

glfwSetKeyCallback(win, [](GLFWwindow * win, int key, int scancode, int action, int mods)
{
    auto dev = reinterpret_cast<rs::device *>(glfwGetWindowUserPointer(win));
    if (action != GLFW_RELEASE) switch (key)
    {
    case GLFW_KEY_R: color_rectification_enabled = !color_rectification_enabled; break;
    case GLFW_KEY_C: align_color_to_depth = !align_color_to_depth; break;
    case GLFW_KEY_D: align_depth_to_color = !align_depth_to_color; break;
    case GLFW_KEY_E:            
        if (dev->supports_option(rs::option::r200_emitter_enabled))
    {
        int value = !dev->get_option(rs::option::r200_emitter_enabled);
        std::cout << "Setting emitter to " << value << std::endl;
        dev->set_option(rs::option::r200_emitter_enabled, value);
    }
                                break;
    case GLFW_KEY_A:
        if (dev->supports_option(rs::option::r200_lr_auto_exposure_enabled))
        {
            int value = !dev->get_option(rs::option::r200_lr_auto_exposure_enabled);
            std::cout << "Setting auto exposure to " << value << std::endl;
            dev->set_option(rs::option::r200_lr_auto_exposure_enabled, value);
        }
        break;
    }

});

Этот код используется в версии librealsense 1.X. Я хотел бы изменить это на код версии librealsense 2.0. Но я не знаю, что делать.

Как мне поменять этот код ??

Спасибо за чтение!

1 Ответ

0 голосов
/ 22 августа 2018

Полезные образцы, чтобы помочь вам с RealSense SDK 2.0 и OpenCV, доступны в репо по адресу /wrappers/opencv

Имейте в виду, что поддерживаемые устройства в SDK 2.0:

Intel® RealSense™ Camera D400-Series
Intel® RealSense™ Developer Kit SR300
...