I'm trying to acquire a depth map, through a snapshot using the kinect, and then to make a 2D plot of this snapshot. The goal is to make a sort of map of the room. The algorithm used is the following:
% Matrice della figura
z=snapshot;
% Dati noti
h=size(z,1); %480
w=size(z,2); %640
% M is a constant based on the field of view angle
M1=1.12032; % Costante per le X
M2=0.84024; % Costante per le Y
for i=1:h <br>
for j=1:w
x(i,j)=(j-(w/2))*(320/w)*M1*z(i,j);
if x(i,j)==0
x(i,j)=NaN;
end
y(i,j)=(i-(h/2))*(240/h)*M2*z(i,j);
if y(i,j)==0
y(i,j)=NaN;
end
end
end
Z=min(z);
X=min(x);
figure
plot(Z,X)
The problem is that this algorithm doesn't do what it should do. Can someone help me?
You can drop the nested loop
x = bsxfun( @times, linspace( -w/2, w/2, w ), z*(320/w)*M1 );
x(x==0) = NaN;
y = bsxfun( @times, linspace( -h/w, h/2, h ).', z*(240/h)*M2 );
y( y==0 ) = NaN;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.