Mike
Mike

Reputation: 113

Extracting Depth images of Kinect using opencv

Does anyone know what is the simplest way to extract the gray-level depth images of Kinect using OpenCV and C++? any source code in this field?

Upvotes: 0

Views: 1543

Answers (3)

Vlad
Vlad

Reputation: 4525

You need to do two things (apart from reading about context, depth generator and initialization of Kinect):

  • Create Mat of the type CV_16U a. context.WaitOneUpdateAll(depth_map); b. Mdepth_original = Mat(h_depth, w_depth, CV_16U, (void*) depth_map.GetData()) c. copy the Mat since it will be destroyed during next read: Mdepth_original.copyTo(depth);
  • Map depth to gray or color. Color seems like a good idea (256^3 levels) but a human eye is more sensitive to the luminance change. Even with 256 levels you can map 10,000 Kinect levels reasonably well using [histogram equalization][1] technique. A simplest way though is to loose precision and just do I(x, y) = 255.0*z(x, y)/z_range

Here is how histogram equalization is implemented in openNI2: https://github.com/OpenNI/OpenNI2/blob/master/Samples/Common/OniSampleUtilities.h

Upvotes: 0

Ian Medeiros
Ian Medeiros

Reputation: 1776

The documentation has everything you need. Can't elaborate better than this.

Upvotes: 0

Eran W
Eran W

Reputation: 1786

if you use OpenNI SDK, you can simply point to the buffer:

//on setup:
xn::DepthGenerator depthGenerator;
xn::DepthMetaData depthMD;
cv::Mat depthWrapper;

//on update loop,
//after context.WaitAnyUpdateAll();
depthGenerator.GetMetaData(depthMD);
depthWrapper = cv::Mat(depthMD.YRes(), depthMD.XRes(), CV_16UC1, (void*) depthMD.Data());

note that depthWrapper is const so you need to clone it in order to manipulate it

Upvotes: 1

Related Questions