資源簡介
簡單背景下在線識別手勢,可與系統(tǒng)進(jìn)行猜拳游戲

代碼片段和文件信息
function?max=gesturef(A)
%max為手指數(shù)目
%?%?figure
%?imshow(A)
%空間轉(zhuǎn)換
[r?c]=size(A);
if?r>800
????A=imresize(A[300?300]);
end
%?figure
%?imshow(A)
%空間轉(zhuǎn)換
%?YUV=rgb2ycbcr(A);%轉(zhuǎn)化為YUV空間
%?imageY=YUV(::1);
%?imageCg=YUV(::2);
%?imageCr=YUV(::3);
se=fspecial(‘a(chǎn)verage‘[33]);%平滑濾波
A=imfilter(Ase);
imageR=A(::1);
imageG=A(::2);
imageB=A(::3);
imageY=16+0.2568*imageR+0.5041*imageG+0.0979*imageB;
imageCg=128-0.318*imageR+0.4392*imageG-0.1212*imageB;
imageCr=128+0.4392*imageR-0.3677*imageG-0.0714*imageB;
Y=find(imageY<=230&imageY>=35);%根據(jù)統(tǒng)計的數(shù)據(jù)找出處在該范圍的像素的下標(biāo)
Cg=find(imageCg<=128&imageCg>=80);
Cr=find(imageCr<=173&imageCr>=131);
index=intersect(Cgintersect(YCr));%找出三個平面的膚色坐標(biāo)交集
BW=im2bw(A);%構(gòu)造二值圖
BW=zeros(size(BW));%全圖置為黑色
BW(index)=1;%把膚色區(qū)域置為白色
%?figure
%?imshow(BW)
IM=?bwareaopen(BWround(1/40*numel(BW)));%把包含像素點少的白色區(qū)域去除
%?figure
%?imshow(IM)
se?=?strel(‘disk‘round(numel(IM)/15000));
IM=imclose(IMse);%閉操作
%?figure
%?imshow(IM)
IM=?bwareaopen(IMround(1/10*numel(IM)));%把包含像素點少的白色區(qū)域去除
%?figure
%?imshow(IM)
se=fspecial(‘a(chǎn)verage‘[55]);%平滑濾波
IM=imfilter(IMse);
%?figure
%?imshow(IM)
%檢測手部長寬比
%?[Lnum]=bwlabel(IM8);%找8連通區(qū)域
%?if?num==0
%?????figure;
%?????imshow(A)
%?end
%?
%?for?n=1:num
%?????[rc]=find(L==n);
%?????x1=min(c);
%?????x2=max(c);
%?????y1=min(r);
%?????y2=max(r);
%?????if?((x2-x1)/(y2-y1))<0.7?||((x2-x1)/(y2-y1))>3
%?????????index=find(L==n);
%?????????IM(index)=0;%把長寬比不合要求的置為背景色
%?????end
%?end
%?[Lnum]=bwlabel(IM8);%找8連通區(qū)域
%?
%?if?num==0
%?????figure;
%?????imshow(IM)
%?end
%腐蝕得到重心
se?=?strel(‘disk‘3);
IM1=imerode(IMse);
[r?c]=find(IM1==1);
while?numel(r)>=500
????IM1=imerode(IM1se);
????[r?c]=find(IM1==1);
end
%?figure
%?imshow(IM1)
centerx=r(1);%得到重心
centery=c(1);
IM(centerxcentery)=0;
%?figure
%?imshow(IM)
%求離重心最遠(yuǎn)的點
[r?c]=find(IM==1);
BW?=?EDGE(IM‘sobel‘);%找到邊緣
[r?c]=find(BW==1);
max=0;
for?k=1:numel(r)
????distance=(r(k)-centerx)^2+(c(k)-centery)^2;
????if?distance>max
????????max=distance;
????????maxx=r(k);maxy=c(k);
????end
end
%找同心圓
d=max^(1/2)/10;
deta=d/4;
angle=0:1/180*(2*pi)/30:2*pi;
for?k=1:10
????r=k*d;
????x1(k:)=round(centerx+sin(angle)*r);%得到圓的坐標(biāo)
????y1(k:)=round(centery+cos(angle)*r);
end
%畫同心圓
%?IM1=IM;
%?[r?c]=size(IM);
%?for?k=1:10
%?????num=length(x1);
%?????for?kk=1:num
%?????????if?x1(kkk)<=0||?x1(kkk)>=r||y1(kkk)<=0||y1(kkk)>=c
%?????????????continue;
%?????????end
%?????????
%?????????IM1(x1(kkk)y1(kkk))=1;
%?????????
%?????end
%????
%?end
%?figure
%?imshow(IM1)
[r?c]=size(IM);
%找黑白色交界的個數(shù)
max=0;
fist=0;%拳頭檢測標(biāo)志
for?k=1:10
????num=length(x1);
????Qj=1;
????Pj=1;
????for?kk=1:num
????????if?x1(kkk)<=0||?x1(kkk)>=r||y1(kkk)<=0||y1(kkk)>=c||kk+1>num||x1(kkk+1)<=0||?x1(kkk+1)>=r||y1(kkk+1)<=0||y1(kkk+1)>=c
????????????continue;
????????end
????????if?IM(x1(kkk)y1(kkk))==0&&IM(x1(kkk+1)y1(kkk+1))==1%Q點坐標(biāo)
????????????if?Qj-Pj>=1
?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4260??2012-05-14?15:59??簡單手勢識別\gesturef.m
?????文件??????12097??2012-06-03?11:38??簡單手勢識別\shot.fig
?????文件???????7882??2012-05-11?20:53??簡單手勢識別\shot.m
?????文件??????22555??2012-05-11?20:21??簡單手勢識別\剪子.jpg
?????文件??????20283??2012-05-11?20:21??簡單手勢識別\布.jpg
?????文件??????17065??2012-05-11?20:20??簡單手勢識別\石頭.jpg
?????目錄??????????0??2012-06-03?11:36??簡單手勢識別
-----------?---------??----------?-----??----
????????????????84142????????????????????7
- 上一篇:空間面板計量
- 下一篇:jnd算法,最小可覺差
評論
共有 條評論