【图像检测】手指指尖的图像采集与检测附matlab代码
1 简介
为克服传统二维彩色图像处理算法易受周围环境,光照变化,背景等因素的影响,提出利用计算机视觉信息,
实现一种快速鲁棒的手势分割与指尖检测算法.首先,根据计算机视觉信息对非人体部分图像进行筛选,得
到包含人手的人体图像;然后对当前得到的人体图像进行直方图分析,计算能够区分人手与非人手的阈值,
并通过该阈值对人体图像进行分割得到人手图像;最后,对人手图像进行形态学处理,计算掌心位置,并提取
手部轮廓,结合人手轮廓关键几何特征对指尖进行有效检测.实验表明,该方法能够实时,有效地对指尖进行
检测.
2 部分代码
3 仿真结果
function indexXY=myConvexHull(x,y)%构成四边形边界n=length(x);%最小最大的x和y坐标
ix=min(x);iy=min(y);ax=max(x);ay=max(y);%这段话其实没什么作用%检测点集,删去内部点,留下
可能构成最小凸包的点test=(x>=ix | x<=ax | y>=iy | y<=ay);index=1:n;index=
(index(test));%可能构成最小凸包的点x=x(test);y=y(test);%可能构成最小凸包的点数
n=length(x);%按y值由小到大排序[y,sindex] = sort(y);x = x(sindex);temp=zeros(n,1);%共
线问题,删去共线的点%及假设几点是在同一条线上,则只取改线的两端点作为凸包点colinear=false;%
if y(1)==y(2) || y(end)==y(end-1)% i=1;% while y(i)==y(i+1)%
i=i+1;% end% if i>2% %计算求得输入点x坐标最小(如果x相等,则比较y是不是最小)
的点,作为第一个点% [x(1:i),xid]=sort(x(1:i),'descend');%
tempindex=sindex(xid);% sindex(1:i)=tempindex; % sindex(2:i-1)=[];%
y(2:i-1)=[];% x(2:i-1)=[];% end% i=1;% if x(1)>x(2)% while
y(end-i+1)==y(end-i)% i=i+1;% end% if i>1% %
colinear=true;% [x(end-i+1:end),xid]=sort(x(end-
i+1:end),'ascend');% tempindex=sindex(end-i+1:end);% sindex(end-
i+1:end)=tempindex(xid);% % sindex(end-i+2:end-1)=[];%
x(end-i+2:end-1)=[];% y(end-i+2:end-1)=[];% end% %
else% while y(end-i+1)==y(end-i)% i=i+1;% end%
if i>1% % colinear=true;% [x(end-
i+1:end),xid]=sort(x(end-i+1:end),'descend');% tempindex=sindex(end-
i+1:end);% sindex(end-i+1:end)=tempindex(xid);% %
sindex(end-i+2:end-1)=[];% x(end-i+2:end-1)=[];% y(end-i+2:end-
1)=[];% end% end% n=length(x);% end%确定方向 %当x(1)>x(2),则方向
为1%否则为-1if x(1)>x(2) orientation=1;else orientation=-1;end%根据
向量的叉乘公式求凸包,向量叉乘大于零为凸包
c=2;i=2;temp(1)=1;temp(2)=2;p1=temp(1);p2=temp(2);%从顶点顺时针扫描一遍while i<=n-1
p3=i+1; cp=orientation*((x(p1)-x(p2))*(y(p3)-y(p2))-(x(p3)-x(p2))*(y(p1)-
y(p2))); if cp>0 temp(c+1)=i+1; p1=p2; p2=p3;
c=c+1; i=i+1; else if c>2 c=c-1; p2=p1;
p1=temp(c-1); else temp(2)=i+1; p2=i+1;
i=i+1; end endendp1=c-1;p1=temp(p1);p2=temp(c);if colinear ||
p1==i-1; i=i-1;end%从最低点顺时针扫描一遍while i>1 p3=i-1; cp=orientation*
((x(p1)-x(p2))*(y(p3)-y(p2))-(x(p3)-x(p2))*(y(p1)-y(p2))); if cp>0
temp(c+1)=i-1; p1=p2; p2=p3; c=c+1; i=i-1;
else c=c-1; p2=p1; p1=temp(c-1);
endendindexXY=index(sindex(temp((1:c))))';end
评论0