bibigone / k4a.net

K4A.Net - Three-in-one .NET library to work with Azure Kinect devices (also known as Kinect for Azure, K4A, Kinect v4). It includes sensor API, recording and playback API, body tracking API. Samples for WPF, .NET Core and Unity are included.
MIT License
165 stars 39 forks source link

depthimage Stream demo #10

Closed jimzou closed 5 years ago

jimzou commented 5 years ago

Thank you very much for your amazing work. Can you share an example of depth image stream demo in unity3D?

baSSiLL commented 5 years ago

Hi! Do you mean rendering depth frames to a texture similarly to how the color stream is rendered in provided Unity sample? Or you want to render 3D point cloud obtained from depth data?

jimzou commented 5 years ago

Hi! Do you mean rendering depth frames to a texture similarly to how the color stream is rendered in provided Unity sample? Or you want to render 3D point cloud obtained from depth data?

I want to render depth frames to a texture!

baSSiLL commented 5 years ago

We don't have a ready code for this. The difference from rendering a color stream is that you cannot just take the raw data and copy it into a texture to get a color image. You need to transform pixels from 16-bit depth values in millimeters to colors (usually using some palette). You can find an example of such transformation made on CPU in DepthImageVisualizer class. Note that you'll need to allow unsafe code in Player Settings to use that code in Unity scripts.

However, if you're looking to implement this in production then it's better to perform depth->color transformation with a custom shader. I suppose you can use Graphics.Blit method for this, with depth data loaded into source texture in R16 format, and custom shader assigned to a material passed to the method.

baSSiLL commented 5 years ago

@jimzou Check out updated Unity sample. I've implemented rendering of the depth stream using shader-based approach outlined above. The most important are new DepthStreamRenderer class and DepthToColor shader.

jimzou commented 5 years ago

Thank you very much for your work.