Ttttt

Only available on StudyMode
  • Download(s) : 55
  • Published : March 29, 2013
Open Document
Text Preview
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153| function []=detect_face(I) close all;Faces=[];numFaceFound=0; I=double(I); H=size(I,1);W=size(I,2);R=I(:,:,1);G=I(:,:,2);B=I(:,:,3);YCbCr=rgb2ycbcr(I);Y=YCbCr(:,:,1);minY=min(min(Y));maxY=max(max(Y));Y=255.0*(Y-minY)./(maxY-minY);YEye=Y;Yavg=sum(sum(Y))/(W*H); T=1;if (Yavg<64)    T=1.4;elseif (Yavg>192)    T=0.6;end if (T~=1)    RI=R.^T;    GI=G.^T;else    RI=R;    GI=G;end C=zeros(H,W,3);C(:,:,1)=RI;C(:,:,2)=GI;C(:,:,3)=B; figure,imshow(C/255);title('Lighting compensation');YCbCr=rgb2ycbcr(C);Cr=YCbCr(:,:,3); S=zeros(H,W);[SkinIndexRow,SkinIndexCol] =find(10<Cr & Cr<45);for i=1:length(SkinIndexRow)    S(SkinIndexRow(i),SkinIndexCol(i))=1;end figure,imshow(S);title('skin');SN=zeros(H,W);for i=1:H-5    for j=1:W-5        localSum=sum(sum(S(i:i+4, j:j+4)));        SN(i:i+5, j:j+5)=(localSum>12);    endend figure,imshow(SN);title('skin with noise removal');L = bwlabel(SN,8);BB  = regionprops(L, 'BoundingBox');bboxes= cat(1, BB.BoundingBox);widths=bboxes(:,3);heights=bboxes(:,4);hByW=heights./widths; lenRegions=size(bboxes,1);foundFaces=zeros(1,lenRegions); rgb=label2rgb(L);figure,imshow(rgb);title('face candidates');for i=1:lenRegions     if (hByW(i)>1.75 || hByW(i)<0.75)        continue;    end    if (heights(i)<20 && widths(i)<20)        continue;    end    CurBB=bboxes(i,:);    XStart=CurBB(1);    YStart=CurBB(2);    WCur=CurBB(3);    HCur=CurBB(4);    rangeY=int32(YStart):int32(YStart+HCur-1);    rangeX= int32(XStart):int32(XStart+WCur-1);    RIC=RI(rangeY, rangeX);    GIC=GI(rangeY, rangeX);    BC=B(rangeY, rangeX);     figure, imshow(RIC/255);    title('Possible face R...
tracking img