How to convert Kinect raw depth info to meters in Matlab?

笑着哭i 提交于 2020-01-10 20:14:11

问题


I have made some research here to understand this topic but I have not achieved good results. I'm working with a Kinect for Windows and the Kinect SDK 1.7. I'm working with matlab to process raw depth map info.

First, I'm using this method (https://stackoverflow.com/a/11732251/3416588) to store Kinect raw depth data to a text file. I got a list with (480x640 = 307200) elements and data like this:

23048
23048
23048
-8
-8
-8
-8
-8
-8
-8
-8
6704
6720
6720
6720
6720
6720
6720
6720
6720
6736
6736
6736
6736
6752
0
0

Then in Matlab I convert this values to binary. So, I get 16-bits numbers. The last three numbers that correspond to player index are "000", so I remove them. Now, from the 13 bits numbers, I remove the more significative, which is always "0".

So, I have made this:

[0,1,1,0,0,0,1,0,0,0,1,1,1,0,0,0] - 16 bits number
[0,1,1,0,0,0,1,0,0,0,1,1,1] - 13 bits number
[1,1,0,0,0,1,0,0,0,1,1,1] - 12 bits number

Then I follow to this procedure (https://stackoverflow.com/a/9678900/3416588) to convert raw-depth info to meters but i get values in the range from -4.7422 to 0.3055. What do they mean?

clc
clear all
close all

%Get raw depth data from .txt
fileID = fopen('C:\Example.txt', 'r');
datos = fscanf(fileID, '%i'); % Data in decimal
fclose(fileID);

% If raw depth data is less than 0, set it to 0
for i = 1 : 640*480
 if(datos(i) < 0)
   datos(i) = 0;
 end
end

% Auxiliar arrays
datosBin = zeros(640*480, 16);
realDepth = zeros(640*480, 12);

% Decimal raw depth data to binary
n = 16;
m = 0;
for i = 1 : 640*480
 a = datos(i);
 datosBin(i,:) = fix(rem(a*pow2(-(n-1):m),2));
end

% Remove player index and msb (more significant bit)
for i = 1 : 640*480
 realDepth(i,:) = datosBin(i,2:13);
end

% Auxiliar array to store raw depth data decimal number
realDepthDec = zeros(640*480,1);

% Raw depth data 12 bits to decimal
for i = 1 : 640*480
 realDepthDec(i) = bin2dec(num2str(realDepth(i,:)));
end

% Auxiliar array
rawDepthMapMeters = zeros(480, 640);

% Create array 640*480 to store bit depth info in meters
for j = 1 : 480
 for i = 1 : 640
   if(realDepthDec(i+j) <= 2046)
    rawDepthMapMeters(j, i) = 0.1236 * tan(realDepthDec(i+j)/2842.5 + 1.1863);
   end
 end
end

Where is my mistake? What am I doing wrong? Thanks in advance.

PS. Sorry for my bad english.


回答1:


In the second article you read, you will see that the method you use is outdated. Read this.

x = (i - w / 2) * (z + minDistance) * scaleFactor
y = (j - h / 2) * (z + minDistance) * scaleFactor
z = z
Where
minDistance = -10
scaleFactor = .0021.
These values were found by hand.

Also you could convert those points to millimeters in your first application as described in the second question

using (var depthFrame = e.OpenDepthImageFrame())
{
    var depthArray = new short[depthFrame.PixelDataLength];
    depthFrame.CopyPixelDataTo(depthArray);

    for (int i = 0; i < depthArray.Length; i++) {
        int depthInMillimeters = 
            depthArray[i] >> DepthImageFrame.PlayerIndexBitmaskWidth;
        // TADAx2!
}


来源:https://stackoverflow.com/questions/22587178/how-to-convert-kinect-raw-depth-info-to-meters-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!