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

📄 facedetectview.cpp

📁 人脸识别因其在安全验证系统、信用卡验证、医学、档案管理、视频会 议、人机交互、系统公安(罪犯识别等)等方面的巨大应用前景而越来越成为 当前模式识别和人工智能领域的一个研究热点。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//12
for(i=(v_top-v_bottom)/10+10;i<Line+4;i++)
{   
   if(t4>=t1&&t4>=t2&&t4>=t3&&t4>=t5&&t4>=t6&&t4>=t7&&t4>Max*0.25)
		{   
	    	Line=i-2;
			break;		
		}
  
   t1=t2;
   t2=t3;
   t3=t4;
   t4=t5;
   t5=t6;
   t6=t7;
   t7=Htemp[i];

   
}

 
/*
///////////////////////////////////////////////////////////////////////////////////
for(j=v_left;j<v_right;j++)
{
	  lOffset = gDib.PixelOffset(Line+v_bottom+(v_top-v_bottom)/2, j, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) = 0;
			        *(lpData + lOffset+2) =255;
					

}
//////////////////////////////////////////////////////////////////////////////////
*/
////////////////////////////////////////////获取左上波谷
///////////////////////////////修改为0.3///////////////////////
int jump=0;
if(Line+2<(v_top-v_bottom)/2)
for(double xishu=0.3;xishu<0.9;xishu=xishu+0.1)
{
    for(i=Line+1;i<(v_top-v_bottom)/2;i++)
	{
	     if(Htemp[i]<=Max*xishu)
		 {
			  L_teye=i;jump=1;
			  break;
		 }
	}
  if(jump==1)
	  break;
	
}

/////////////////////////////////////////获取左下波谷
if((Line-1)>0)
    for(i=Line-1;i>=0;i--)
	{
	  if(Htemp[i]<=Max*0.3)
		 {
			 L_beye=i;
			 break;
		 }
	}

L_EyeMiddleLine=Line;
////////////////////////////////////////////////////////////////////
 
////////////////////////////////////////获取左左边线
	 
  H_lleye=0;
  H_lreye=0;
  for(j=((v_right-v_left)/5)*3+((v_right-v_left)/5)/2;j<(v_right-v_left);j++)
  {   int  Count=0;
	  for(i=L_beye+(v_top-v_bottom)/2;i<L_teye+(v_top-v_bottom)/2;i++)
	  {
	  if(WhiteBlack[i][j]==0)
	   Count++;
	  }
	   if(Count<(L_teye-L_beye)/5||j==(v_right-v_left-1))
	   {H_lleye=j;
	    break;
	   }
  }

  ////////////////////////////////////获取右边线
  for(j=((v_right-v_left)/5)*3+((v_right-v_left)/5)/2;j>(v_right-v_left)/2;j--)
  {   int  Count=0;
	  for(i=L_beye+(v_top-v_bottom)/2;i<L_teye+(v_top-v_bottom)/2;i++)
	  {
	  if(WhiteBlack[i][j]==0)
	   Count++;
	  }
	   if(Count<(L_teye-L_beye)/5||j==(v_right-v_left)/2+1)
	   {H_lreye=j;
	    break;
	   }
  }
   

/////////////////////////////////////////右眼定位///////////////////////////
	   Max=0;
	   k1_Middle=(v_right-v_left)/5;
	   k_Middle=(v_top-v_bottom)/2;
	   int R_EyeMiddleLine=0;
	   int Count=0;
	       R_teye=0;

       for(i=0;i<(v_top-v_bottom)/2+1;i++)
		          Htemp[i]=0;
	  for(i=(v_top+v_bottom)/2,k=0;i<=v_top;i++,k++)
		for(j=v_left,k1=0;j<=v_left+(v_right-v_left)/2;j++,k1++)
          if(WhiteBlack[k+k_Middle][k1]==0)
		  {
                Htemp[k]++;
		  }
  
		  
for(i=5;i<(v_top-v_bottom)/2-2;i++)
	{
		if(Htemp[i]>Max)
		{   
			Max=Htemp[i];
	    	Line=i;
			
		}
       
	}
int SLine=Line;
/*
///////////////////////////////////////////////////////////////////////////////////
for(j=v_left;j<v_right;j++)
{
	  lOffset = gDib.PixelOffset(Line+v_bottom+(v_top-v_bottom)/2, j, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) = 0;
			        *(lpData + lOffset+2) =255;
					

}
//////////////////////////////////////////////////////////////////////////////////

*/
	
/*
if(Line>(v_top-v_bottom)/2-4||Max<((v_right-v_left)/5)*0.2)
  {
   ::AfxMessageBox("请确认图片中是否有人脸!");
    return false ;
  }
*/
///////////////////////////////////获取右波峰
 int x1=Htemp[5];
 int x2=Htemp[6];
 top=0;
for(i=8;i<Line+4;i++)
{   
   if(top>x1&&top>x2&&top>Max*0.25)
		{   
	    	Line=i-2;
			break;		
		}
   else
   {
    if(x1>x2)
		t=x1;
	else
		t=x2;

	top=t;

   }
   x1=Htemp[i];
   x2=Htemp[++i];
   
}

if(Line<L_EyeMiddleLine-15)
{
 t=0;
 x1=Htemp[L_EyeMiddleLine-15];
 x2=Htemp[L_EyeMiddleLine-14];
 top=0;
 
for(i=L_EyeMiddleLine-13;i<L_EyeMiddleLine+10;i++)
{   
   if(top>x1&&top>x2&&top>Max*0.25)
		{   
	    	Line=i-2;
			break;		
		}
   else
   {
    if(x1>x2)
		t=x1;
	else
		t=x2;

	top=t;

   }
   x1=Htemp[i];
   x2=Htemp[++i];
   
}


}
/*
//////////////////////////////////眼睛中线////////////////////////////////
for(j=v_left;j<v_right;j++)
{
	  lOffset = gDib.PixelOffset(Line+v_bottom+(v_top-v_bottom)/2, j, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) = 0;
			        *(lpData + lOffset+2) =255;
					

}
//////////////////////////////////////////////////////////////////////////////////

*/
	/*	
  if(Line<(v_top-v_bottom)/2-4)
  {
   ::AfxMessageBox("请确认图片中是否有人脸!");
    return false ;
  }
*/
  R_EyeMiddleLine=Line;

/////////////////////////////////获取右上波谷	
jump=0;
R_teye=0;
if(R_EyeMiddleLine+5<(v_top-v_bottom)/2)
for(double xishu=0.3;xishu<0.9;xishu=xishu+0.1)
{	 
   for(i=Line+1;i<(v_top-v_bottom)/2;i++)
	{
	     if(Htemp[i]<=Max*xishu)
		 {
			  R_teye=i;jump=1;
			  break;
		 }
	}
   if(jump==1)
	   break;
	
}

/////////////////////////////////获取右下波谷
     R_beye=0;
    if((R_EyeMiddleLine-5)>0)
      for(i=Line-1;i>=0;i--)
	{
	  if(Htemp[i]<=Max*0.3)
		 {
			 R_beye=i;
			 break;
		 }
	}

///////////////////////////////获取右左线
  H_rleye=0;
  H_rreye=0;
  for(j=((v_right-v_left)/5)*1+((v_right-v_left)/5)/2;j<(v_right-v_left)/2;j++)
  {   int  Count=0;
	  for(i=R_beye+(v_top-v_bottom)/2;i<R_teye+(v_top-v_bottom)/2;i++)
	  if(WhiteBlack[i][j]==0)
	   Count++;
	   if(Count<(R_teye-R_beye)/5)
	   {H_rleye=j;
	    break;
	   }
  }
/////////////////////////////////获取右右线
  for(j=((v_right-v_left)/5)+((v_right-v_left)/5)/2;j>0;j--)
  {   int  Count=0;
	  for(i=R_beye+(v_top-v_bottom)/2;i<R_teye+(v_top-v_bottom)/2;i++)
	  if(WhiteBlack[i][j]==0)
	   Count++;
	   if(Count<(R_teye-R_beye)/5)
	   {H_rreye=j;
	    break;
	   }
  }
  
  if((H_rleye-H_rreye)<(H_lleye-H_lreye))
	  H_rreye=H_rleye-(H_lleye-H_lreye);
  else
	  H_lleye=H_lreye+(H_rleye-H_rreye);
  if(((L_teye-L_beye)-(R_teye-R_beye))>2)
	  L_teye=L_beye+(R_teye-R_beye);
  if(((R_teye-R_beye)-(L_teye-L_beye))>2)
	  R_teye=R_beye+(L_teye-L_beye);
////////////////////////////////////////////////////////////

  if(R_beye>L_teye||R_beye==L_teye||R_teye<L_beye||R_teye==L_beye)
  {
   ::AfxMessageBox("请确认图片中是否有人脸!以及脸部的获取是否整确!");
    return false ;
  }

///////////////////////////////////////////////////////////

    int m_top=(v_top-v_bottom)/2+L_teye;
    int m_bottom=(v_top-v_bottom)/2+L_beye;
    int m_left=H_lreye;
    int m_right=H_lleye;

  int L_EyeTopY=L_teye+(v_top-v_bottom)/2+v_bottom;
  int L_EyeTopX=TopPoint(m_top, m_bottom, m_left,m_right)+v_left;
      DrawCrossX(L_EyeTopX,L_EyeTopY);
  
	 
  L_EyeLY=(L_teye-L_beye)/3+(v_top-v_bottom)/2+v_bottom+L_beye+1;
  L_EyeLX=v_left+H_lleye;
      DrawCrossX(L_EyeLX,L_EyeLY);

  L_EyeRY=(L_teye-L_beye)/3+(v_top-v_bottom)/2+v_bottom+L_beye+1;
  L_EyeRX=v_left+H_lreye;
  DrawCrossX(L_EyeRX,L_EyeRY);

  int L_EyeBY=v_bottom+(v_top-v_bottom)/2+L_beye;
  int L_EyeBX=L_EyeTopX;
         DrawCrossX(L_EyeBX,L_EyeBY);
		  
////////////////////////////////////右眼///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
  m_top=(v_top-v_bottom)/2+R_teye;
  m_bottom=(v_top-v_bottom)/2+R_beye;
  m_left=H_rreye;
  m_right=H_rleye;

  int R_EyeTopY=R_teye+(v_top-v_bottom)/2+v_bottom;  
  int R_EyeTopX=TopPoint(m_top, m_bottom, m_left,m_right)+v_left;
  DrawCrossX(R_EyeTopX,R_EyeTopY);

  R_EyeLY=(R_teye-R_beye)/3+(v_top-v_bottom)/2+v_bottom+R_beye+1;
  R_EyeLX=v_left+H_rleye;
          DrawCrossX(R_EyeLX,R_EyeLY);

  R_EyeRY=(R_teye-R_beye)/3+(v_top-v_bottom)/2+v_bottom+R_beye+1;
  R_EyeRX=v_left+H_rreye;
     DrawCrossX(R_EyeRX,R_EyeRY);

  int R_EyeBY=v_bottom+(v_top-v_bottom)/2+R_beye;
  int R_EyeBX= R_EyeTopX;
       DrawCrossX(R_EyeBX,R_EyeBY);

	 
	   /*
//////////////////////////////////////////////////////////////////////////



for(j=v_left+H_lreye;j<v_left+H_lleye;j++)
{
	  lOffset = gDib.PixelOffset(L_teye+(v_top+v_bottom)/2, j, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) = 0;
			        *(lpData + lOffset+2) =255 ;
					
      lOffset = gDib.PixelOffset(L_beye+(v_top+v_bottom)/2, j, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) =0 ;
			        *(lpData + lOffset+2) =255;
					


}
for(i=(v_bottom+v_top)/2+L_beye;i<(v_bottom+v_top)/2+L_teye;i++)
{
	  lOffset = gDib.PixelOffset(i,v_left+H_lleye, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) = 0;
			        *(lpData + lOffset+2) =255 ;
					
        lOffset = gDib.PixelOffset(i, v_left+H_lreye, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) =0 ;
			        *(lpData + lOffset+2) =255;
					


}

for(j=v_left+H_rreye;j<v_left+H_rleye;j++)
{
	  lOffset = gDib.PixelOffset(R_teye+(v_top+v_bottom)/2, j, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) = 0;
			        *(lpData + lOffset+2) =255;
					
        lOffset = gDib.PixelOffset(R_beye+(v_top+v_bottom)/2, j, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) =0 ;
			        *(lpData + lOffset+2) =255;
					


}

for(i=(v_bottom+v_top)/2+R_beye;i<(v_bottom+v_top)/2+R_teye;i++)
{
	  lOffset = gDib.PixelOffset(i,v_left+H_rleye, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) = 0;
			        *(lpData + lOffset+2) =255 ;
					
        lOffset = gDib.PixelOffset(i, v_left+H_rreye, gwBytesPerLine);
					*(lpData + lOffset) = 0;
			        *(lpData + lOffset+1) =0 ;
			        *(lpData + lOffset+2) =255;
					


}
*/

return true;
}

int CFaceDetectView::TopPoint(int m_top,int m_bottom,int m_left,int m_right)
{
    int Max=0;
	int L,R;
   for(int j=m_left;j<m_right;j++)
   { int Count=0;
	   for(int i=m_bottom;i<m_top;i++)
		   if(WhiteBlack[i][j]==0)
	             Count++;
		   if(Max<Count)
		   {
			   Max=Count; L=j;
		   }
   }

 Max=0;
 for(j=m_right;j>m_left;j--)  
   { int Count=0;
	   for(int i=m_bottom;i<m_top;i++)
		   if(WhiteBlack[i][j]==0)
	             Count++;
		   if(Max<Count)
		   {
			   Max=Count; R=j;
		   }
   }
   return (L+R)/2;



}


/////////////////////////////////////鼻子定位////////////////////////////////////////
void CFaceDetectView::FixeNose()
{   
	int N_top;
	int i,j;
	LPBYTE lpData;
	lpData = gDib.FindDIBBits(hDIB);
	WORD gwBytesPerLine = gDib.BytePerLine(hDIB);
	int lOffset;
	if(R_beye>L_beye)
		N_top=L_beye;
	else
		N_top=R_beye;
    T_NoseMiddleLine=0;
	    B_NoseMiddleLine=0;
		int a=(H_rleye-H_lreye)*0.5;
	for(i=(v_top-v_bottom)/2+N_top-10;i>(v_top-v_bottom)/4;i--)
		{   int Count=0;
			for(j=H_rleye;j<H_lreye;j++)
			{
				if(WhiteBlack[i][j]==0)
					Count++;
			}
			if(((v_right-v_left)/5)*0.3<Count)
			{  
			    T_NoseMiddleLine=i; 
				break;
			}
        }

  
	for(i=T_NoseMiddleLine-3;i>(v_top-v_bottom)/4;i--)
		{   int Count=0;
			for(j=((v_right-v_left)/5)*2;j<((v_right-v_left)/5)*3;j++)
			{
				if(WhiteBlack[i][j]==0)
					Count++;
			}
			if(((v_right-v_left)/5)*0.5>Count)
			{
			    B_NoseMiddleLine=i; 
				break;
			}
        }



  ///////////////////////鼻左////////////////////////////////////////
H_lnose=0;
	for(j=(H_lreye+H_rleye)/2;j<((v_right-v_left)/5)*4;j++)
		{   int Count=0;
			for(i=B_NoseMiddleLine;i<T_NoseMiddleLine;i++)
			{
				if(WhiteBlack[i][j]==0)

⌨️ 快捷键说明

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