Items with no label
3335 Discussions

About CreateDepthImageMappedToColor function

dzhou8
Novice
1,470 Views

Hi,everyone~

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 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

# include

# include

using namespace std;

using namespace cv;

using namespace Intel::RealSense;

void main()

{

PXCSenseManager *sm = PXCSenseManager::CreateInstance();

sm->Init();

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(y);

if (d>0)

p[x] = d * 256 / 1200;

else

p[x] = 0;

}

framepic.convertTo(output, CV_8UC1, 1);

imshow("depth picture", output); waitKey(1);

depthPXCImage->ReleaseAccess(&d2c_data);

}

sm->ReleaseFrame();

}

sm->Release();

}

Thank you for any help.

1 Solution
dzhou8
Novice
272 Views

I find the solution of null value of the device pointer.

We need enablestream, such as:

PXCSenseManager *sm = PXCSenseManager::CreateInstance();

sm->EnableStream(PXCCapture::STREAM_TYPE_COLOR);

sm->EnableStream(PXCCapture::STREAM_TYPE_DEPTH);

sm->Init();

PXCCapture::Device *device = sm->QueryCaptureManager()->QueryDevice();

But the code still doesn't work well, something wrong with changing PXCImage picture to CV::Mat.

I am trying to solve the new problem.

View solution in original post

0 Kudos
4 Replies
idata
Employee
272 Views

Hi Dan,

 

 

Thanks for your interest in the Intel RealSense Technology.

 

 

We would like to suggest you to take a look at the Projection.cpp sample under RSSDK\samples\core directory that we believe you'll find very useful. This sample demonstrate how to use the SDK Projection functions to map or project coordinates among the color image coordinate system, the depth image coordinate system, and the camera coordinate system. Additionally, you can find more information here: https://software.intel.com/sites/landingpage/realsense/camera-sdk/v2016r3/documentation/html/index.html?sample_projection_cpp.html Sample: Projection [C++].

 

 

Hope this information helps.

 

 

Regards,

 

-Yermi A.

 

0 Kudos
dzhou8
Novice
272 Views

Hi Yermi,

Thank you for your reply.

I really need to take a closer look at the Projection.cpp sample with MFC framework.

I appreciate your help very much.

0 Kudos
idata
Employee
272 Views

Hi Dan,

 

 

Great to know that you have found that helpful.

 

 

Have a nice day!

 

 

Regards,

 

-Yermi A.

 

0 Kudos
dzhou8
Novice
273 Views

I find the solution of null value of the device pointer.

We need enablestream, such as:

PXCSenseManager *sm = PXCSenseManager::CreateInstance();

sm->EnableStream(PXCCapture::STREAM_TYPE_COLOR);

sm->EnableStream(PXCCapture::STREAM_TYPE_DEPTH);

sm->Init();

PXCCapture::Device *device = sm->QueryCaptureManager()->QueryDevice();

But the code still doesn't work well, something wrong with changing PXCImage picture to CV::Mat.

I am trying to solve the new problem.

0 Kudos
Reply