4 Replies Latest reply on May 17, 2017 2:18 AM by dan_dan

    About CreateDepthImageMappedToColor function



          It's me again,  I am very sorry that I'm a rookie in realsense.

          I need to map depth image to color image space. I find a function name"CreateDepthImageMappedToColor" which may be useful to me.

          I find a code snippet at  https://software.intel.com/en-us/node/657586

          And I complete the code on this basis. (Maybe it's completed...)

          There is no build error. But when I run, an interruption occurred at the beginning.

          When I single-step debug, I find that the pointer *device is NULL. (The interrupt may be due to this reason...)

          Can you help me to modify the code? Or do you have other completed C++ code about alignment of depth image and color image??

          So sorry for my poor programming, here is my full code:

      #include "stdio.h"
      #include "pxcsensemanager.h"
      #include "pxcsession.h"
      #include "util_render.h"
      #include "opencv.hpp"
      #include <math.h>
      #include <iostream>
      #include <pxcprojection.h>
      using namespace std;
      using namespace cv;
      using namespace Intel::RealSense;
      void main()
        PXCSenseManager *sm = PXCSenseManager::CreateInstance();
        PXCCaptureManager *cmanager = sm->QueryCaptureManager();
        PXCCapture::Device *device = cmanager->QueryDevice();
        PXCProjection *projection = device->CreateProjection();
        PXCCapture::Sample *sample;
        PXCImage::ImageData  d2c_data;
        PXCImage::ImageInfo  d2c_info;
        Mat framepic = Mat(480, 640, CV_8UC1);
        ushort* p;
        Mat output;
        while (sm->AcquireFrame(true) >= PXC_STATUS_NO_ERROR) 
        sample = sm->QuerySample();
        if (sample->depth) {
        PXCImage *depthPXCImage = projection->CreateDepthImageMappedToColor(sample->depth, sample->color);
        d2c_info = depthPXCImage->QueryInfo();
        depthPXCImage->AcquireAccess(PXCImage::ACCESS_READ, &d2c_data);
        ushort* dpixels = (ushort*)d2c_data.planes[0];
        int dpitch = d2c_data.pitches[0] / sizeof(ushort);
        for (int y = 0; y<(int)d2c_info.height; y++)
        for (int x = 0; x<(int)d2c_info.width; x++)
        ushort d = dpixels[y*dpitch + x];
        p = framepic.ptr<ushort>(y);
        if (d>0)
        p[x] = d * 256 / 1200;
        p[x] = 0;
        framepic.convertTo(output, CV_8UC1, 1);
        imshow("depth picture", output); waitKey(1);


         Thank you for any help.