clear all
close all

addpath('Mex')

% Start the Kinect Process
KinectHandles=mxNiCreateContext();

figure;
I=mxNiPhoto(KinectHandles); I=permute(I,[3 2 1]);
D=mxNiDepth(KinectHandles); D=permute(D,[2 1]);
subplot(1,2,1),h1=imshow(I); 
subplot(1,2,2),h2=imshow(D,[0 9000]); colormap('jet');
    
for i=1:10
    I=mxNiPhoto(KinectHandles); I=permute(I,[3 2 1]);
    D=mxNiDepth(KinectHandles); D=permute(D,[2 1]);
    set(h1,'CDATA',I);
    set(h2,'CDATA',D);
    drawnow; 
end

figure
h2=imshow(D,[0 9000]);
[yMax,xMax]=size(D);
disp(['Distanz: ',num2str(D(yMax/2,xMax/2)),' cm']);
hold on
plot(xMax/2,yMax/2,'r+')
plot(100,1,'go') % Achtung x,y in Bildkoordinaten 100 rechts, 200 unten

Messwerte(1,:)=[30 40 45 50  55  60  70   80  90   100 110   120 130 140 150 160 170 200 250 300]; % Entfernung in mm
Messwerte(2,:)=[ 0  0  0  0 558 607 706  805  908 1010 1108 1202 1302 1398 1516 1601 1705 1993 2485 3010]; % Xtion Depth Messwert

figure
plot(Messwerte(1,:),Messwerte(2,:),'b.-')
xlabel('Entfernung in cm')
ylabel('Xtion Depth Messwert in mm')


% Stop the Kinect Process
mxNiDeleteContext(KinectHandles);
