- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi guys!
I want to show to the user a Depth Image mapped to Color.I want to do this by using a cv::Mat.
I used the projection->CreateDepthImageMappedToColor(PXCImage *depth, PXCImage *color);
p and I managed to pass the pxcimage data to a cv::Mat MappedDepthMat(480,640,CV_16UC1); by using the following function:
void CopyDepthImageMappedToColor_ToMat(PXCImage *ColorImage,PXCImage *DepthImage,PXCImage::ImageData &data,cv::Mat &MappedDepthMat) { PXCImage* mapped=projection->CreateDepthImageMappedToColor(DepthImage,ColorImage); pxcStatus sts=mapped->AcquireAccess(PXCImage::ACCESS_READ,&data); if(sts==PXC_STATUS_NO_ERROR ) { memcpy(MappedDepthMat.data,data.planes[0],sizeof(unsigned short) * 640 * 480); MappedDepthMat=MappedDepthMat*255; mapped->ReleaseAccess(&data); } }
You can see that I multiply each element by 255.If I don't do this,then I get a black screen because of the Mat.The original values of MappedDepthMat before I multiply by 255 give me the distance in mm,correct? What is the maximum value?Can I somehow normalize the whole thing and have max depth=1 and min depth=0?
What is the original range?When I call the above mentioned function what is the max value of pixel?Can I somehow change the maximum value and still get the required result?
At the end of the day,I want to have a Mat with a range of 0-1 but with float values in between.I need this to match with the opengl's z-buffer values.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could you change
pxcStatus sts=mapped->AcquireAccess(PXCImage::ACCESS_READ,&data);
to
pxcStatus sts=mapped->AcquireAccess(PXCImage::ACCESS_READ,PXCImage::PIXEL_FORMAT_DEPTH_F32, &data);
and let me know if you still have such issue. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, This my code, it succeeeded, and maybe it will help you.
Mat depthimage8;
depthimage8.create(480,640,CV_8UC1);
PXCImage::ImageData data_depth; unsigned short *depth_data;
sample->depth->AcquireAccess(PXCImage::ACCESS_READ,PXCImage::PIXEL_FORMAT_DEPTH, &data_depth);
depth_data = (unsigned short*)data_depth.planes[0];
unsigned char cVal;
for(int y=0; y<H; y++)
{
for(int x=0; x<W; x++)
{
if(depth_data[y*W+x] > fMaxValue) //fMaxValue = 1000
depth_data[y*W+x] = fMaxValue;
cVal = (unsigned char)((1.0*depth_data[y*W+x])/fMaxValue*255);
if(cVal!=0)
cVal = 255 - cVal;
depthimage8.at<unsigned char>(y,x) = cVal;
}
}

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page