資源簡介
快速人臉定位matlab程序,準確的確定人臉,然后定位
代碼片段和文件信息
clear?all
close?all
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%?讀入待檢測圖像
x=?imread(‘1.jpg‘);
xx=x;
figure
imshow(x);
fR=xx(::1);
fG=xx(::2);
fB=xx(::3);
f=1/9*ones(3);%低通濾波器,濾除高頻噪聲
filtered_fR=imfilter(fRf);
filtered_fG=imfilter(fGf);
filtered_fB=imfilter(fBf);
x_filtered=cat(3filtered_fRfiltered_fGfiltered_fB);
figure
imshow(x_filtered);
I=rgb2ycbcr(x);????????%顏色空間轉換?
gray=rgb2gray(x);
figure
imshow(gray);
[abc]=size(I);?%得到圖像的像素點個數
cb=double(I(::2));
cr=double(I(::3));
for?i=1:a
????for?j=1:b
????????w=[cb(ij)cr(ij)];
????????m=[117.4316?148.5599];
????????n=[260.1301?12.1430;12.1430?150.4574];
????????p(ij)=exp((-0.5)*(w-m)*inv(n)*(w-m)‘);%算某象素點的概率
????????if?(p(ij)<0.5)?
????????????p(ij)=0;
????????else?
????????????p(ij)=1;
????????end
????end
end?
fenge=p;
figure
imshow(fenge);
SE?=?strel(‘square‘3);?
imf=imopen(pSE);?????????%開運算(即先腐蝕再膨脹),消除雜散點?
xingtai=imf;
figure
imshow(xingtai);
%figureimshow(Ibwopen);?
%Ibwoc=imclose(IbwopenSE);??????%閉運算,去掉由于開運算引入的許多缺口?
%figureimshow(Ibwoc);?
%imf=imfill(Ibwoc‘holes‘);??????%填充孔洞?
%%%%%%%%%%%%%%%%%%%%%%%根據填充率去除手腳、胳膊等非人臉區域%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[Lnum]=bwlabel(imf8);?????%連通區域標記?
B=zeros(size(imf));
for?i=1:num
????Area(i)=bwarea(L==i);%計算每個皮膚區域的面積
end
for?i=1:num
????[rc]?=?find(L==i)?;
????left(i)=min(c);
????right(i)=max(c);
????up(i)=min(r);
????down(i)=max(r);
end
for?i=1:num?
????%計算各矩形區域面積
????Rect_Area(i)=(down(i)-up(i))*(right(i)-left(i));
end
%計算各區域的填充率
Ratio=Area./Rect_Area;
for?i=1:n
- 上一篇:電動汽車整車實車控制模型
- 下一篇:MATLAB樣例之雅克比迭代法
評論
共有 條評論