PART 1: Open the depth camera and get the data
%
% cj_compile_script
%
%% Directories copied from OpenNIDevEnvironment
OPENNI2_INCLUDE = '/F:\351project\Include';
OPENNI2_REDIST = '/F:\351project\Redist';
%% Compile call
mex(['-L' OPENNI2_REDIST],'-lOpenNI2',['-I' OPENNI2_INCLUDE],'mxNI.cpp');
[frame, frame_index, timestamp] = mxNI(2); framed = double(frame)./double(max(frame(:)));imshow(framed);
PART 2: Gesture recognition
clear
load('fuperfecthand.mat')
b=framed;
figure(1)
imshow(b);// show the orginal depth image
a=edge(b);// find the edge of that image
pause
figure(2)
imshow(a);
carray=zeros(1,1000);
max=0;
max_x=0;
max_y=0;
for i=1:240;
c=0;
for j=1:280;
if (abs(b(i,j)-b(i,j+1))<0.001)&&(abs(b(i,j)-1)>0.2)
c=c+1;
if j>max_y;
max_y=j;
end
end
end
carray(1,i)=c;
if c>max;
max=c;
max_x=i;
end
end // find the reference point
a(max_x,max_y-50)=1;
a1=a(max_x-80:max_x+30,max_y-60:max_y+30);// find the hand
pause
figure(3)
imshow(a1)
max_xx=81;
max_yy=11;
k=a1;
a = size(k,1);
b = size(k,2);
x = zeros(1,a);
y = zeros(1,b);
count = 1;
for i = 1:a;
for j = 1:b;
if k(i,j) == 1
x(count) = i-max_xx;
y(count) = j-max_yy;
count=count+1;
end
end
end // put the image into the catersain coordinate
pause
figure(4)
plot(x,y,'r.');
[theta,r] = cart2pol(x,y);// converte the image into polar coordinate
pause
figure(5)
plot(theta,r,'*');
[xu, di]=sort(theta);
rw=r;
length=size(r,2);
for jj=1:length;
rw(jj)=r(di(jj));
end // put those plots into a matrix
pause
figure(6)
plot(rw)
xlable=1:length;
lev=5 ;
xd=wden(rw,'sqtwolog','s','sln',lev,'sym8');// use wden filter
xd1=xd;
pause
figure(7)
plot(xd1)
for jjj=1:5
for iii=2:length-4;
if(xd(iii)-xd(iii+1))>0&&(rw(iii-1)-rw(iii))<0
xd(iii)=(xd(iii+1)+xd(iii-1))/2;
end
if(xd(iii)-xd(iii+1))<0&&(rw(iii-1)-rw(iii))>0
xd(iii)=(xd(iii+1)+xd(iii-1))/2;
end
end
end // use our own filter
pause
figure(8)
plot(xd)
peak=0;
for ii=8:length-10;
if (xd(ii)-xd(ii+1))>0&&(xd(ii)-xd(ii+2))>0&&(xd(ii)-xd(ii+3))>0&&(xd(ii)-xd(ii+4))>0&&(xd(ii)-xd(ii+5))>0&&(xd(ii)-xd(ii+6))>0&&(xd(ii)-xd(ii+7))>0&&(xd(ii-1)-xd(ii))<0&&(xd(ii-2)-xd(ii))<0&&(xd(ii-3)-xd(ii))<0&&(xd(ii-4)-xd(ii)<0&&(xd(ii-5)-xd(ii))<0&&(xd(ii-6)-xd(ii))<0)
peak=peak+1;
end
end // count peaks
pause
peak