librekinect
librekinect copied to clipboard
Colour Depth
Hi,
I'm working on implementing a simple SLAM without hopefully using ROS, and only C++,OPENCV. I have been able to get the raw sensor values (IR depth sensor), RGB image however not simultaneously on my Banana Pi. Ignoring the RGB Image, would is be possible for me to convert the IR depth sensor to a colour depth like this: https://graphics.stanford.edu/~mdfisher/Images/KinectSensors.png if so how or do i required the RGB image...
I solved this by creating three vectors of size 256 for red, green and blue, and generated values to form a rainbow pattern with one color for each depth value.
For the values I used this tutorial: http://krazydad.com/tutorials/makecolors.php
Here's how I generated the vectors:
//RGB values for coloring the depth image
std::vector<double> red;
std::vector<double> green;
std::vector<double> blue;
for(int i = 0; i < 256; ++i){
red.push_back(sin((i-50)*0.05 + 0) * 127 + 128);
green.push_back(sin((i-50)*0.05 + 2) * 127 + 128);
blue.push_back(sin((i-50)*0.05 + 4) * 127 + 128);
}
And here's an example of how to color the image:
void color(cv::Mat &mat){
uchar* mPixel;
double depth;
for (int i = 0; i < mat.rows; ++i){
mPixel = mat.ptr<uchar>(i);
for (int j = 0; j < mat.cols; ++j){
depth = *mPixel;
*mPixel++ = blue[depth];
*mPixel++ = green[depth];
*mPixel++ = red[depth];
}
}
}
@jonathanknorn good job :+1: