2

Now, i'm using real sense D435 camera.

I installed sdk 2.0 full package and upgraded camera version 5.1 to 5.9(latest version).

I want to code to get color image and depth image using 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.

wows
  • 41
  • 1
  • 5

2 Answers2

2

The D400 series cameras aren't compatible with the old Realsense SDK, only the new librealsense SDK, available here: 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

jb455
  • 100
  • 1
  • 7
2

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)

#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;
}
Prototype
  • 222
  • 1
  • 8