【问题标题】:intel real sense programming about librealsense2关于librealsense2的英特尔实感编程
【发布时间】:2018-12-10 10:34:37
【问题描述】:

我想获得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
  2. 以 PNG 格式保存彩色图像和深度图像

我可以得到关于2code。 但是,当我按下“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 版本代码。但我不知道该怎么办。

如何更改此代码??

感谢阅读!

【问题讨论】:

    标签: c++ realsense


    【解决方案1】:

    /wrappers/opencv 的 repo 中提供了帮助您使用 RealSense SDK 2.0 和 OpenCV 的有用示例

    请记住,SDK 2.0 支持的设备是:

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

    【讨论】:

    • 欢迎来到 Stack Overflow!包含指向外部资源的链接以提供上下文非常好。但是,根据 Stack Overflow 的政策,要求读者咨询外部资源才能提供帮助的答案帖子根本不被视为合法答案。您能否将关键信息直接添加到您的帖子中?您不妨咨询How to Answer
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多