⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cropface.m

📁 It is for Face Recognition
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function cropFace()
%   z.li, 06-18-2004
%   find face id and relevance to a model with certain distance metric
% function dependency:
%   - n/a
% input:
%   img     - input image
%   lex,ley, rex, rey - eyes location
%   side, top, bottom - face model spec, in length of eye distances
%   fw, fh  - desired face size
% output:
%   vec  - fwxfh x1  
%  'cropFaceSave.jpg' - optionally saved face. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function [vec]=cropFace(img, lex, ley, rex, rey, side, top, bottom, fw, fh)
function [vec]=cropFace(img, lex, ley, rex, rey, side, top, bottom, fw, fh)

  dbg ='n';
  if dbg == 'y'
     k=5;     
     img   =    loadATTFace(24, k);
     eyes  = load('attface-eyes24.dat');
     eyes  = fix(eyes);
     lex=eyes(k,1);ley=eyes(k,2);rex=eyes(k,3);rey=eyes(k,4);     
     side = 0.5; top=-1.0; bottom= 1.6;
     fw=16; fh=20;
     hold on;plot(lex, ley, '+r'); plot(rex, rey, '+m'); 
  end
  % const
  dbgPlot   = 'n';
  hEq       = 'n';      % no hist equalization
  saveFace  = 'y';

  [imgH imgW]=size(img);
  d = norm(([lex ley] - [rex rey]), 2); 
% find the face icon window
  faceW = fix((1+2*side)*d);
  faceH = fix((top+bottom)*d);
  leftMargin = fix(side*d);
  topMargin = fix(top*d);
  
  % upper left corner
  ulX = lex - leftMargin; 
  ulY = ley - topMargin;
  % lower right corner
  lrX = ulX + faceW -1;
  lrY = ulY + faceH -1; 
  % boundary check
  if ulX < 1 | ulY < 1 | lrX > imgW | lrY > imgH
     % out of pic
     vec = -1;
     return;
  end 
  % detection window
  if dbgPlot=='y'
      imshow(img, 256); hold on; 
      plot(lex, ley, '+r'); plot(rex, rey, '+m'); hold on;
      px =[ulX lrX]; py=[ulY ulY]; plot(px,py,'.',px,py,'-g');
      px =[ulX ulX]; py=[ulY lrY]; plot(px,py,'.',px,py,'-g');
      px =[ulX lrX]; py=[lrY lrY]; plot(px,py,'.',px,py,'-g');
      px =[lrX lrX]; py=[lrY ulY]; plot(px,py,'.',px,py,'-g');
  end

  % facial area
  face(1:faceH,1:faceW) = img(ulY:lrY,ulX:lrX);  
  if hEq == 'y'
     face = histeq(face);  
  end
  % save face image
  if saveFace == 'y'
     imwrite(face, 'cropFaceSave.jpg', 'jpg');
  end
  faceIconImg = imresize(face, [fh fw], 'bilinear');
  vec = im2vec(faceIconImg);

    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -