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

📄 getferetfaceicon.m

📁 It is for Face Recognition
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function getFeretFaceIcon()
%   z.li, 12-16-2003.
%   show face with gnd truth
% function dependency:
%   - loadFeretFace()
% input:
%   gndTruth - 
%   side, up, low - margin in eye distance
%   hEq - do histogram equ ? 'y' or 'n'
%   k    - offs
%   fw, fh - icon size
% output:
%   faceIcon - facial area sub image 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function [faceIcon]=getFeretFaceIcon(gndTruth, hEq, k, side, up, low, fw, fh)
function [faceIcon]=getFeretFaceIcon(gndTruth, hEq, k, side, up, low,fw, fh)
  dbg='n';   
  if dbg=='y'
      truth = load('feretGndTruth.dat');
      gndTruth = truth;
      hEq = 'n';
      fw = 15; fh=12;
      k=1752; 
      side=0.5; up=1.6; low=-0.2;
  end    

  dbgplot = 'n';
  
  % var
  reX = gndTruth(k,2);reY = gndTruth(k,3);
  leX = gndTruth(k,4);leY = gndTruth(k,5);

  moX = gndTruth(k,6);moY = gndTruth(k,7);
  ntX = gndTruth(k,8);ntY = gndTruth(k,9);

  % check for gnd truth 
  if reX== -1 |reY== -1 |leX== -1 |leY== -1 | abs(leY-reY) > 12
     faceIcon = -1;
     return;
  end

  id = sprintf('%s', gndTruth(k,10:26));
  faceImg = loadFeretFace(id);
  [fht, fwid] = size(faceImg);
  
  % eyes - mouth  triangle
  d = norm(([leX leY] - [reX reY]), 2); % eye distance
  
  %a = norm(([leX leY] - [moX moY]), 2);
  %b = norm(([moX moY] - [reX reY]), 2);
  %h = moY - 0.5*(leY+reY);

  % margins in times d, so total is (top+botom)*d x (1+2*side)*d
  top = up; bottom = low;

  % 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 = max(1, leX - leftMargin); 
  ulY = leY - topMargin;
  % lower right corner
  lrX = ulX + faceW -1;
  lrY = ulY + faceH -1;  

  % facial area  
  face =  faceImg(ulY:lrY,ulX:lrX); 
  if hEq == 'y'
     face = histeq(face);  
  end
  meanFaceLuma = fix(mean(mean(face)));
    
  faceIconImg = imresize(face, [fh fw], 'bilinear');
  faceIcon = im2vec(faceIconImg);
  
  if dbgplot == 'y'
      axis off; 
      imshow(faceImg, 256); hold on;       
      % eyes, mouth and nose tip
      plot(leX, leY, 'or');plot(reX, reY, 'om');plot(moX, moY, '+r');plot(ntX, ntY, '*g');

      % detection window
      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');

      colormap('gray');
      imagesc(face);
      str = sprintf('%d: %d', k, meanFaceLuma);
      title(str);
  end

⌨️ 快捷键说明

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