In pca algorithm code faces are detected where there is no face in image.plz help

%face recognition_ Nicholas Joy %Loading of training set database %the training is made up of 400 images. %the images will be used for the recognition process. w=load_database(); %loading database size (w) %%initializations %the initial conditions are initialized. %the new image input and video configuarion. %that will be used for recognition is set. v = videoinput('winvideo', [1]); %initialize video input triggerconfig (v, 'manual') %configure trigger v.FramesPerTrigger = 1; set (v,'TriggerFrameDelay',20); %Set trigger delay preview(v); start(v); trigger(v) %Triggering snapshot set(v, 'ReturnedColorSpace','grayscale') rgbImage = getdata(v); stop(v); fullImageFileName = fullfile(pwd, 'new.pgm'); imwrite(rgbImage,fullImageFileName); B=imread('new.pgm'); r = imresize(B, [112 92]); %Resizing image to 112x92 imwrite(r,'new.pgm'); im =(r); %r contains the image we use to test the algorithm tempimg = im(:,:,1); r = reshape(tempimg, 10304,1); v=w; %v contains the database N=50; %number of signatures used for each image* %%subtracting the mean from v O=uint8(ones(1,size(v,2))); m=uint8(mean(v,2)); %m is the mean of all images vzm=v-uint8(single(m)*single(O)); %vzm is v with the mean removed %%calculating eigenvectors of the correlation matrix % we are picking N of the 400 eigenfaces. L=single(vzm)'*single(vzm); [V,D]=eig(L); V=single(vzm)*V; V=V(:,end:-1:end-(N-1)); %pick the eigenvalues corresponding to the %10 largest eigenvalues %%calculating the signature for each image cv=zeros(size(v,2),N); for i=1:size(v,2); cv(i,:)=single(vzm(:,i))'*V; %each row in cv is the signature for one image end %%recognition %now, we run the algorithm and see if we ca correctly recognize the face. figure (1) subplot(121); imshow(reshape(r,112,92));title('Looking for ...', 'FontWeight','bold','Fontsize',16,'color','red'); subplot(122); p=r-m; %subtract the mean s=single(p)'*V; z=[]; for i=1:size(v,2) z=[z,norm(cv(i,:)-s,2)]; if(rem(i,20)==1),imshow(reshape(v(:,i),112,92)),end; drawnow; end [a,i]=min(z); subplot(122); imshow(reshape(v(:,i),112,92));title('Found','FontWeight','bold','Fontsize',16,'color','red');

Answers (0)

Asked:

on 21 Oct 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!