Mapping RGB and depth (Kinect v2)
Show older comments
Hi everyone, for my project, I'm working with the Kinect v2 and I have to map the depth information onto the RGB images to process them: in particular, I need to know which pixels in the RGB images are in a certain range of distance (depth) along the Z axis; I'm acquiring all the data with a C# program and saving them as images.
I had a look on the internet and I found some equations to map depth and RGB info here. I am actually able to get the intrinsic parameters for the single camera calibration using a checkerboard recorded from both the RGB camera (1920x1080) and the IR sensor (512x424) and processing them with MatLab Camera Calibrator app, but I'm stuck doing the stereo calibration (to find the rotation and translation matrices), because MatLab Stereo Camera Calibrator doesn't accept pair of images with different resolution.
I've also tried some other method with no results; It would be great if anyone could help me figuring out what I have to do in order to solve my problem. Thanks very much!
9 Comments
dodesheide
on 2 Jun 2016
Edited: Walter Roberson
on 6 Nov 2018
Matlab Stereo Camera Calibrator is not the right way, because it is not a Stereo Calibration. Take a look at this matlab calibration: https://github.com/kapibara/ToF-Calibration or take a look at the paper "Joint Depth and Color Camera Calibration with Distortion Correction" from Herrera. That would help you to map color to depth.
Walter Roberson
on 29 Oct 2018
Edited: Walter Roberson
on 29 Oct 2018
Muhammad Hammad Malik
on 6 Nov 2018
hello all, i want to do depth-color image registration but do not know how to do it, kindly guide me for this. if anyone have working code or wahtever, kindly help me. thanks
Walter Roberson
on 6 Nov 2018
Muhammad Hammad Malik: the link I posted for codefull has MATLAB code for RGB registration with depth for Kinect.
Muhammad Hammad Malik
on 6 Nov 2018
Edited: Walter Roberson
on 6 Nov 2018
i tried to use that link but i am unable. kindly check it what things i need to do.see attach code. thanks
function [aligned] = ...
depth_rgb_registration('F:\kinectdata\cloud\tomato.ply', 'F:\kinectdata\color\tomato1.jpg',...
1.1752e+03, 1.2589e+03, 849.6059, 726.8106,...
1.0585e+03, 1.1341e+03, 965.1123, 583.2686,...
[1.0000 -0.0055 0.0003 -78.2239;
0.0055 1.0000 0.0002 31.3206;
-0.0003 -0.0002 1.0000 -8.0845])
fx_rgb_len = 3.28135;
fy_rgb_len = 3.51571;
fx_d_len = 3.64132;
fy_d_len = 3.90295;
depthHeight=424;
depthWidth=512;
depthHeight = size('F:\kinectdata\cloud\tomato.ply', 1);
depthWidth = size('F:\kinectdata\cloud\tomato.ply', 2);
% Aligned will contain X, Y, Z, R, G, B values in its planes
aligned = zeros(depthHeight, depthWidth, 6);
for v = 1 : (depthHeight)
for u = 1 : (depthWidth)
% Apply depth intrinsics
z = single('F:\kinectdata\cloud\tomato.ply'(v,u)) / depthScale;
x = single((u - 849.6059) * z) / 1.1752e+03;
y = single((v - 726.8106) * z) / 1.2589e+03;
% Apply the extrinsics
transformed = ([1.0000 -0.0055 0.0003 -78.2239;
0.0055 1.0000 0.0002 31.3206;
-0.0003 -0.0002 1.0000 -8.0845] * [x;y;z;1])';
aligned(v,u,1) = transformed(1);
aligned(v,u,2) = transformed(2);
aligned(v,u,3) = transformed(3);
end
end
for v = 1 : (depthHeight)
for u = 1 : (depthWidth)
% Apply RGB intrinsics
x = (aligned(v,u,1) * 1.0585e+03 / aligned(v,u,3)) + 965.1123;
y = (aligned(v,u,2) * 1.1341e+03/ aligned(v,u,3)) + cy_rgb;
% "x" and "y" are indices into the RGB frame, but they may contain
% invalid values (which correspond to the parts of the scene not visible
% to the RGB camera.
% Do we have a valid index?
if (x > rgbWidth || y > rgbHeight ||...
x < 1 || y < 1 ||...
isnan(x) || isnan(y))
continue;
end
% Need some kind of interpolation. I just did it the lazy way
x = round(x);
y = round(y);
aligned(v,u,4) = single('F:\kinectdata\color\tomato1.jpg'(y, x, 1);
aligned(v,u,5) = single('F:\kinectdata\color\tomato1.jpg'(y, x, 2);
aligned(v,u,6) = single('F:\kinectdata\color\tomato1.jpg'(y, x, 3);
end
end
end
Walter Roberson
on 6 Nov 2018
A function statement cannot have any numeric constants or any quoted strings or any {}. You need to put back the variable names and you need to call the function passing in the necessary information.
Also note that taking size() of a single quoted string is an operation that is asking about the number of characters in the literal string. No attempt is made to see if the string resembles a file name or to see how much information might be stored in the file.
Muhammad Hammad Malik
on 6 Nov 2018
alright, thanks, but i can understand a little bit, because i dont know much about programming. if you can then kindly solve the issue. i shall be very thankful to you.thanks
Walter Roberson
on 6 Nov 2018
Following some links I see that someone has created a small toolbox at https://sourceforge.net/projects/kinectcalib/
Muhammad Hammad Malik
on 15 Nov 2018
thanks for this, i used this but it is always saying that device is not detected but when i run in some other code then device is working
Accepted Answer
More Answers (1)
Muhammad Hammad Malik
on 29 Oct 2018
0 votes
hello all, i want to do depth-color image registration but do not know how to do it, kindly guide me for this. if anyone have working code or wahtever, kindly help me. thanks
2 Comments
Ankit Jaiswal
on 22 Feb 2019
Hi, Did you get success in this?
Muhammad Hammad Malik
on 10 Jun 2019
Edited: Walter Roberson
on 11 Jun 2019
Categories
Find more on Kinect For Windows Sensor in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!