Sei sulla pagina 1di 3

Skin Color Model is a very effective method for face detection.

The following matlab example shows how to implement face detection using skin color. Sample code: %Detection of Face on the basis of skin color clear all; close all; clc % vid = videoinput('winvideo', 1, 'YUY2_320x240'); % vid.ReturnedColorSpace = 'rgb'; % snap = getsnapshot(vid); % I=snap; I=imread('D:\face7.jpg'); % imshow(I),title('Image:1'); cform = makecform('srgb2lab'); J = applycform(I,cform); % figure;imshow(J),title('Image:2'); K=J(:,:,2); % figure;imshow(K),title('Image:3'); L=graythresh(J(:,:,2)); BW1=im2bw(J(:,:,2),L); % figure;imshow(BW1),title('Image:4'); M=graythresh(J(:,:,3)); % figure;imshow(J(:,:,3)),title('Image:5'); BW2=im2bw(J(:,:,3),M); % figure;imshow(BW2),title('Image:6'); O=BW1.*BW2;%logic and Bounding box % figure;imshow(O),title('Image:O=BW1.*BW2'); P=bwlabel(O,8);%with 8 neighborhood % calculating acreage of every connected area and converting %the data of cell into array BB=regionprops(P,'Boundingbox'); BB1=struct2cell(BB); %saving the begining point of connected frame and its high and wide BB2=cell2mat(BB1); % show the target in rectangular frame [s1 s2]=size(BB2); figure;imshow(I),title('I'); mx=0; count=0; for k=3:4:s2-1 %BB2(1,k)wide ,BB2(1,k+1)high if(BB2(1,k)/BB2(1,k+1)) < 1.8 &&....

(BB2(1,k)/BB2(1,k+1)) > 0.4 &&.... (BB2(1,k)*BB2(1,k+1)) > 5000 count=count+1; % considering the areas which have 0.4<W/H<1.8 and their pixels % acreage is bigger than 1000 as face hold on; rectangle('Position',[BB2(1,k-2),BB2(1,k-1),BB2(1,k),BB2(1,k+1)],'EdgeColor','r' ); slot{count}=[BB2(1,k-2),BB2(1,k-1),BB2(1,k),BB2(1,k+1)]; end end copy=I; img=rgb2gray(I);

bwa1 = edge(img,'sobel'); bwa2 = edge(img,'canny'); bwa=bwa1+bwa2; figure,imshow(bwa),title('Image:bwa');

for i=1:size(slot,2) set=slot{i}; x=round(set(1)); y=round(set(2)); w=set(3); h=set(4); ay=y; get=zeros(h,w+1); for yy=1:h ax=x; for xx=1:w+1 get(yy,xx)=bwa(ay,ax); ax=ax+1;

end

ay=ay+1; end figure,imshow(get); end lines=bwlabel(get,8); at=max(lines); expression=max(at); text(-39,15,['You Have Teen Ka = ',num2str(expression),' ea!! '],'Color','R','FontSize',10,'FontWeight','bold');

figure,imshow(copy),title('Image:copy'); text(-40,15,['You Have Teen Ka To Much is = ',num2str(expression),' ea!! '],'Color','R','FontSize',15,'FontWeight','bold'); if (expression<=20) T = 'Oh, your face as clear as baby.'; T2 ='What did you eat as you clear this face.'; elseif (20<expression && expression<45 ) T = 'Oh, your face is starting to get wrinkles.'; T2 ='You should consult doctor to inject botox.'; else T = 'Oh, the wrinkles on your face much more then.'; T2 ='You should consult doctor to Surgery.'; end text(1,200,[' ',num2str(T)],'Color','b','FontSize',10,'FontWeight','bold'); text(1,215,[' ',num2str(T2)],'Color','b','FontSize',10,'FontWeight','bold');

Potrebbero piacerti anche