请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册
查看: 8230|回复: 5

人脸检测

[复制链接]

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
发表于 2016-12-25 17:54:58 | 显示全部楼层 |阅读模式
GML AdaBoost Matlab Toolbox:
游客,如果您要查看本帖隐藏内容请回复

1、人脸检测---基于肤色检测的实现
2、人脸检测-基于模板匹配的实现
这两种方法都是基于肤色特征实现的,是比较经典的人脸检测实现的算法,

MATLAB工具箱函数使用如下:


Adaboost的几个人脸检测网站
游客,如果您要查看本帖隐藏内容请回复


基于adaboost的人脸检测算法的matlab实现过程
http://www.ilovematlab.cn/forum.php?mod=viewthread&tid=122887
http://www.ilovematlab.cn/thread-34196-1-1.html
http://www.ilovematlab.cn/thread-474554-1-1.html
http://www.thinkface.cn/forum-73-1.html





算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
 楼主| 发表于 2016-12-25 17:56:32 | 显示全部楼层
       最基本的整个流程框架:整个task被看作是模式识别,或者说机器学习的一个task因此分成learning和detecting的过程,前者学习出人脸模型,后者使用这个模型进行监测;
       learning阶段:使用人脸区域和非人脸区域,每个区域是一张图,对每张图提取特征,比如haar-like特征,这个很经典,提取完了再reshape一下,所有reshape过的特征塞给adaboost分类器进行训练;
       测试阶段就是滑窗法进行检测了:在测试图像的空间尺度金字塔的每一层上,每一个可能的位置都提取haar-like特征,然后塞给分类器(也就是加载了刚刚训练好的模型的分类器),它会算出一个response值,根据阈值将这个response划分为人脸和非人脸。
算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复 支持 反对

使用道具 举报

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
 楼主| 发表于 2016-12-25 20:54:41 | 显示全部楼层
创建gabor滤波下的ffnn神经网络,进行人脸预测
  1. net = network;
  2. net.numInputs = 1;
  3. net.numLayers = 2;

  4. net.biasConnect = [1;1];
  5. net.inputConnect = [1 ;...
  6.                     0 ];
  7. net.layerConnect = [0 0 ;...
  8.                     1 0 ];               
  9. net.outputConnect = [0 1];               
  10. net.targetConnect = [0 1];

  11. netInputs = ones (2160,2);
  12. netInputs (1:2160,1)= -1;
  13. net.inputs{1}.range = netInputs;
  14. net.layers{1}.size = 100;
  15. net.layers{2}.size = 1;
  16. net.layers{1:2}.transferFcn = 'tansig';
  17. net.layers{1:2}.initFcn = 'initnw';

  18. net.initFcn = 'initlay';
  19. net.performFcn = 'msereg';
  20. net.trainFcn = 'trainscg';
  21. net = init(net)
  22. save net net
复制代码
然后再分块预测
  1. % Version : 5.4
  2. % Date : 12.26.2010
  3. % Author  : Omid Sakhi
  4. % <a href="http://www.facedetectioncode.com" target="_blank">http://www.facedetectioncode.com</a>

  5. function im_out = imscan (net,im)

  6. close all

  7. %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. % PARAMETERS
  9. SCAN_FOLDER = 'imscan/';
  10. UT_FOLDER = 'imscan/under-thresh/';
  11. TEMPLATE1 = 'template1.png';      
  12. TEMPLATE2 = 'template2.png';      
  13. Threshold = 0.5;
  14. DEBUG = 0;
  15. %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  16. warning off;
  17. delete ([UT_FOLDER,'*.*']);
  18. delete ([SCAN_FOLDER,'*.*']);
  19. if (DEBUG == 1)
  20.     mkdir (UT_FOLDER);
  21.     mkdir (SCAN_FOLDER);
  22. end

  23. [m n]=size(im);

  24. %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. % First Section
  26. C1 = mminmax(double(im));
  27. C2 = mminmax(double(imread (TEMPLATE1)));
  28. C3 = mminmax(double(imread (TEMPLATE2)));
  29. Corr_1 = double(conv2 (C1,C2,'same'));
  30. Corr_2 = double(conv2 (C1,C3,'same'));
  31. Cell.state = int8(imregionalmax(Corr_1) | imregionalmax(Corr_2));
  32. Cell.state(1:13,:)=-1;
  33. Cell.state(end-13:end,:)=-1;
  34. Cell.state(:,1:9)=-1;
  35. Cell.state(:,end-9:end)=-1;
  36. Cell.net = ones(m,n)*-1;
  37. [LUTm LUTn]= find(Cell.state == 1);
  38. imshow(im);
  39. hold on
  40. plot(LUTn,LUTm,'.y');pause(0.01);

  41. %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. % Second Section
  43. while (1==1)
  44.     [i j] = find(Cell.state==1,1);
  45.     if isempty(i)
  46.         break;
  47.     end
  48.     imcut = im(i-13:i+13,j-9:j+8);
  49.     Cell.state(i,j) = -1;
  50.     Cell.net(i,j) = sim(net,im2vec(imcut));   
  51.     if Cell.net(i,j) < -0.95
  52.         for u_=i-3:i+3
  53.             for v_=j-3:j+3
  54.                 try
  55.                     Cell.state(u_,v_)=-1;
  56.                 end
  57.             end
  58.         end        
  59.         plot(j,i,'.k');pause(0.01);
  60.         continue;
  61.     elseif Cell.net(i,j) < -1*Threshold
  62.         plot(j,i,'.m');pause(0.01);
  63.         continue;
  64.     elseif Cell.net(i,j) > 0.95
  65.         plot(j,i,'.b');pause(0.01);
  66.         for u_=i-13:i+13
  67.             for v_=j-9:j+9
  68.                 try
  69.                     Cell.state(u_,v_)=-1;
  70.                 end
  71.             end
  72.         end
  73.     elseif Cell.net(i,j) > Threshold
  74.         plot(j,i,'.g');pause(0.01);
  75.     elseif Cell.net(i,j) < Threshold        
  76.         plot(j,i,'.r');pause(0.01);                        
  77.     end        
  78.     for i_=-1:1
  79.         for j_=-1:1
  80.             m_=i+i_;                    
  81.             n_=j+j_;            
  82.             if (Cell.state(m_,n_) == -1 || Cell.net(m_,n_)~=-1)
  83.                 continue;
  84.             end            
  85.             imcut = im(m_-13:m_+13,n_-9:n_+8);
  86.             Cell.net(m_,n_) = sim(net,im2vec(imcut));
  87.             if Cell.net(m_,n_) > 0.95
  88.                 plot(n_,m_,'.b');pause(0.01);
  89.                 for u_=m_-13:m_+13
  90.                     for v_=n_-9:n_+9
  91.                         try
  92.                             Cell.state(u_,v_)=-1;
  93.                         end
  94.                     end
  95.                 end
  96.                 continue;
  97.             end           
  98.             if Cell.net(m_,n_) > Threshold
  99.                 Cell.state(m_,n_) = 1;
  100.                 plot(n_,m_,'.g');pause(0.01);
  101.                 if (DEBUG == 1)
  102.                     imwrite(imcut,[SCAN_FOLDER,'@',int2str(m_),',',int2str(n_),' (',int2str(fix(Cell.net(m_,n_)*100)),'%).png']);                       
  103.                 end
  104.             else
  105.                 Cell.state(m_,n_) = -1;
  106.                 plot(n_,m_,'.r');pause(0.01);
  107.                 if (DEBUG == 1)
  108.                     imwrite(imcut,[UT_FOLDER,'@',int2str(m_),',',int2str(n_),' (',int2str(fix(Cell.net(m_,n_)*100)),'%).png']);                       
  109.                 end
  110.             end  
  111.         end
  112.     end
  113. end

  114. %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  115. % Third Section
  116. hold off
  117. figure;imshow (Cell.net,[]);
  118. xy_ = Cell.net > Threshold;
  119. xy_ = imregionalmax(xy_);
  120. xy_ = imdilate (xy_,strel('disk',2,4));
  121. [LabelMatrix,nLabel] = bwlabeln(xy_,4);
  122. CentroidMatrix = regionprops(LabelMatrix,'centroid');
  123. xy_ = zeros(m,n);
  124. for i = 1:nLabel
  125.     xy_(fix(CentroidMatrix(i).Centroid(2)),...
  126.            fix(CentroidMatrix(i).Centroid(1))) = 1;
  127. end
  128. xy_ = drawrec(xy_,[27 18]);
  129. im_out (:,:,1) = im;
  130. im_out (:,:,2) = im;
  131. im_out (:,:,3) = im;
  132. for i = 1:m
  133.     for j=1:n
  134.         if xy_(i,j)==1
  135.             im_out (i,j,1)=0;
  136.             im_out (i,j,2)=255;
  137.             im_out (i,j,3)=0;            
  138.         end
  139.     end
  140. end
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复 支持 反对

使用道具 举报

0

主题

47

帖子

1

金钱

新手上路

Rank: 1

积分
48
发表于 2018-6-26 19:49:05 | 显示全部楼层
太好了,谢谢
回复 支持 反对

使用道具 举报

0

主题

6

帖子

1

金钱

新手上路

Rank: 1

积分
7
发表于 2018-11-22 10:13:05 | 显示全部楼层
111111111111111111111111111111111111
回复 支持 反对

使用道具 举报

0

主题

11

帖子

1

金钱

新手上路

Rank: 1

积分
12
发表于 2019-3-13 11:17:37 | 显示全部楼层
666666666666666666666666666
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-3-29 05:29 , Processed in 0.224400 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表