简体   繁体   English

vs2015中的英特尔实感sdk编程

[英]intel real sense sdk programming in vs2015

Now, i'm using real sense D435 camera. 现在,我正在使用真实感D435相机。

I installed sdk 2.0 full package and upgraded camera version 5.1 to 5.9(latest version). 我安装了sdk 2.0完整软件包,并将相机版本5.1升级到5.9(最新版本)。

I want to code to get color image and depth image using visual studio 2015. 我想使用Visual Studio 2015进行编码以获取彩色图像和深度图像。

so i coded 所以我编码

#include <iostream>
#include "pxcsession.h"
#include "pxcprojection.h"
#include "pxcsensemanager.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <Windows.h>
#pragma comment(lib, "winmm.lib")

using namespace cv;
using namespace std;

class RealSenseAsenseManager
{
public:
    ~RealSenseAsenseManager()
    {
        if (senseManager != 0) {
            senseManager->Release();
        }
    }

    void initialize()
    {

        senseManager = PXCSenseManager::CreateInstance();
        if (senseManager == nullptr) {
            throw std::runtime_error("SenseManager failed");
        }

        pxcStatus sts = senseManager->EnableStream(
            PXCCapture::StreamType::STREAM_TYPE_DEPTH,
            DEPTH_WIDTH, DEPTH_HEIGHT, DEPTH_FPS);
        if (sts < PXC_STATUS_NO_ERROR) {
            throw std::runtime_error("Depth stream activation failed");
        }


        sts = senseManager->Init();
        if (sts < PXC_STATUS_NO_ERROR) {
            throw std::runtime_error("Pipeline Initialzation failed");
        }


        senseManager->QueryCaptureManager()->QueryDevice()->SetMirrorMode(
            PXCCapture::Device::MirrorMode::MIRROR_MODE_HORIZONTAL);
    }

    void run()
    {

        while (1) {

            updateFrame();

            auto ret = showImage();
            if (!ret) {
                break;
            }
        }
    }

private:

    void updateFrame()
    {

        pxcStatus sts = senseManager->AcquireFrame(false);
        if (sts < PXC_STATUS_NO_ERROR) {
            return;
        }


        const PXCCapture::Sample *sample = senseManager->QuerySample();
        if (sample) {

            updateDepthImage(sample->depth);
        }

        senseManager->ReleaseFrame();
    }


    void updateDepthImage(PXCImage* depthFrame)
    {
        if (depthFrame == 0) {
            return;
        }


        PXCImage::ImageData data;
        pxcStatus sts = depthFrame->AcquireAccess(
            PXCImage::Access::ACCESS_READ,
            PXCImage::PixelFormat::PIXEL_FORMAT_RGB32, &data);
        if (sts < PXC_STATUS_NO_ERROR) {
            throw std::runtime_error("Taking Depth image failed");
        }


        PXCImage::ImageInfo info = depthFrame->QueryInfo();
        depthImage = cv::Mat(info.height, info.width, CV_8UC4);
        memcpy(depthImage.data, data.planes[0], data.pitches[0] * info.height);

        depthFrame->ReleaseAccess(&data);
    }


    bool showImage()
    {
        if (depthImage.rows == 0 || (depthImage.cols == 0)) {
            return true;
        }


        cv::imshow("Depth Image", depthImage);

        int c = cv::waitKey(10);
        if ((c == 27) || (c == 'q') || (c == 'Q')) {
            // ESC|q|Q for Exit
            return false;
        }

        return true;
    }

private:

    cv::Mat depthImage;
    PXCSenseManager *senseManager = 0;

    const int DEPTH_WIDTH = 640;
    const int DEPTH_HEIGHT = 480;
    const int DEPTH_FPS = 30.0f;

};
void main()

    {
        try {

            RealSenseAsenseManager deep;

            deep.initialize();

            deep.run();
        }
        catch (std::exception& ex) {
            std::cout << ex.what() << std::endl;
        }
    }

But this error appears. 但是出现此错误。

        sts = senseManager->Init();
        if (sts < PXC_STATUS_NO_ERROR) {
            throw std::runtime_error("Pipeline Initialzation failed");
        }

Pipeline Initialization failed <- 管道初始化失败<-

I don't know how to solve this problem. 我不知道如何解决这个问题。

The depth camera connection is not likely to be wrong. 深度相机连接不太可能出错。

The color image is displayed. 显示彩色图像。 Only depth video is not available. 仅深度视频不可用。

How I can solve this problem?? 我该如何解决这个问题?

Thank you for reading my question. 感谢您阅读我的问题。

The D400 series cameras aren't compatible with the old Realsense SDK, only the new librealsense SDK, available here: https://github.com/IntelRealSense/librealsense . D400系列摄像机与旧的Realsense SDK不兼容,仅与新的librealsense SDK不兼容,可从以下网址获取: https : //github.com/IntelRealSense/librealsense

A sample showing how to get the colour and depth images streaming is here: https://github.com/IntelRealSense/librealsense/tree/master/examples/capture 此处显示了如何获取彩色和深度图像流的示例: https : //github.com/IntelRealSense/librealsense/tree/master/examples/capture

You can start by using one of the provided examples. 您可以使用提供的示例之一开始。

The code below configures the camera and renders Depth & RGB data: (the example.hpp header is located in the main repo /examples dir) 下面的代码配置相机并渲染深度和RGB数据:( example.hpp标头位于主存储库/examples目录中)

#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
#include "example.hpp"          // Include short list of convenience functions for rendering

// Capture Example demonstrates how to
// capture depth and color video streams and render them to the screen
int main(int argc, char * argv[]) try
{
    rs2::log_to_console(RS2_LOG_SEVERITY_ERROR);
    // Create a simple OpenGL window for rendering:
    window app(1280, 720, "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;

    // 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM