Convert Kin Depth to RGB

I use OpenNI and OpenCV (but without the latest code with openni support). If I just send the depth channel to the screen, it will look dark and it's hard to understand something. Therefore, I want to show the depth channel to the user in color, but I can’t find how to do this without losing accuracy. Now I do it like this:

xn::DepthMetaData xDepthMap; depthGen.GetMetaData(xDepthMap); XnDepthPixel* depthData = const_cast<XnDepthPixel*>(xDepthMap.Data()); cv::Mat depth(frame_height, frame_width, CV_16U, reinterpret_cast<void*>(depthData)); cv::Mat depthMat8UC1; depth.convertTo(depthMat8UC1, CV_8UC1); cv::Mat falseColorsMap; cv::applyColorMap(depthMat8UC1, falseColorsMap, cv::COLORMAP_AUTUMN); depthWriter << falseColorsMap; 

But in this case, I get worse (lose details) than, for example, kinects software for windows shows. Therefore, I am looking for a function in OpenNI or OpenCV with better conversion.

+4
source share
2 answers

Try the following:

 const float scaleFactor = 0.05f; depth.convertTo(depthMat8UC1, CV_8UC1, scaleFactor); imshow("depth gray",depthMat8UC1); 

Play with the value to get the result you are happy with

+1
source

ghttps: //github.com/OpenNI/OpenNI2/blob/master/Samples/Common/OniSampleUtilities.h the link is a code for histogram alignment. In short, this makes the probability of each level equal and optimizes the display between 10,000 levels and 255 levels. That's why the yellowish Kinect card looks better than the naive i = 255 * z / z_range.

NOTE. Do not use color for visualization, as the human eye is more sensitive to changes in brightness than to changes in color. Thus, with 255 brightness levels you will get better contrast than with 255 * 255 * 255 color levels. If you still decide to go on the spotlight of the color image, use the HSV color space, where you can manipulate the hue of 0..360 degrees, the value is 1..0 and it is better to set the saturation to max. Map depth to hue and value, convert to RGB and display. Then go back to align the histogram;)

+2
source

Source: https://habr.com/ru/post/1494250/


All Articles