Kinect Depth Image

kinect, kinect-sdk, opencv

Solution

The stripes that you see, are due to the `wrapping` of depth values, as caused by the `%256` operation. Instead of applying the modulo operation (`%256`), which is causing the bands to show up, remap the depth values along the entire range, e.g.:

BYTE intensity = depth == 0 || depth > 4095 ? 0 : 255 - (BYTE)(((float)depth / 4095.0f) * 255.0f);

in case your max depth is 2048, replace the 4095 with 2047.

More pointers:

- the Kinect presumably returns a 11bit value (0-2047) but you only use 8bit (0-255).

- new Kinect versions seem to return a 12bit value (0-4096)

- in the Kinect explorer source code, there's a file called `DepthColorizer.cs` where most of the magic seems to happen. I believe that this code makes the depth values so smooth in the kinect explorer - but I might be wrong.

Problem

In my application I am getting the depth frame similar to the depth frame retrieved from Depth Basics Sample. What I don't understand is, why are there discrete levels in the image? I don't know what do I call these sudden changes in depth values. Clearly my half of my right hand is all black and my left hand seems divided into 3 such levels. What is this and how do I remove this? When I run the KinectExplorer Sample app I get the depth as follows. This is the depth image I want to generate from the raw depth data. I am using Microsoft Kinect SDK's (v1.6) NuiApi along with OpenCV. I have the following code: ``` BYTE *pBuffer = (BYTE*)depthLockedRect.pBits; //pointer to data having 8-bit jump USHORT *depthBuffer = (USHORT*) pBuffer; //pointer to data having 16-bit jump int cn = 4; this->depthFinal = cv::Mat::zeros(depthHeight,depthWidth,CV_8UC4); //8bit 4 channel for(int i=0;i<this->depthFinal.rows;i++){ for(int j=0;j<this->depthFinal.cols;j++){ USHORT realdepth = ((*depthBuffer)&0x0fff); //Taking 12LSBs for depth BYTE intensity = (BYTE)((255*realdepth)/0x0fff); //Scaling to 255 scale grayscale this->depthFinal.data[i*this->depthFinal.cols*cn + j*cn + 0] = intensity; this->depthFinal.data[i*this->depthFinal.cols*cn + j*cn + 1] = intensity; this->depthFinal.data[i*this->depthFinal.cols*cn + j*cn + 2] = intensity; depthBuffer++; } } ```

Original source