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

📄 facereg.cpp

📁 人脸识别
💻 CPP
字号:
// (c) by Fraunhofer IIS, Department Electronic Imaging
//
// PROJECT     : FaceReg   
//
// AUTHOR      : Meng Minyao
//
// DESCRIPTION : Bla
//
// CHANGED BY  : $LastChangedBy: mengmo $
//
// DATE        : $LastChangedDate: 2008-10-9 12:06:36 +0200 (Tue, 06 Sep 2005) $
//
// REVISION    : $LastChangedRevision: 8597 $
//
// start below with your implementation

#include "stdafx.h"
#include "FaceReg.h"

int main(int iArgc, char** argv)
{
   cout << "Entering main" << endl;
	
   char* firstImage = 0; 
   char* secondImage = 0; 
   ipParser xParser(iArgc, argv);
   xParser.SetFilter("-a %s -m %s");
   xParser.ParseArgs(0,&firstImage,&secondImage);

   if(firstImage == 0)
      cout << "No first image loaded" << endl;
   else
      cout << "First image is: " << firstImage << endl;
   if(secondImage == 0)
      cout << "No second image loaded" << endl;
   else
      cout << "Second image is: " << secondImage << endl;

   //Try to load images from the given images pathes.
   ipByteAoi* fImage = new ipByteAoi(); 
   ipByteAoi* sImage = new ipByteAoi(); 

   try{
      ipImageCache::GetImage(*fImage, std::string(firstImage), true);
      ipImageCache::GetImage(*sImage,std::string(secondImage), true);
   }catch(...)
   {
      cout << "Failed to load images" << endl;
      return 0; 
   }

   unsigned char* pfImageR = fImage->GetPixAdr(0,0,0);
   unsigned char* pfImageG = fImage->GetPixAdr(0,0,1);
   unsigned char* pfImageB = fImage->GetPixAdr(0,0,2);
   
   unsigned char* psImage = sImage->GetPixAdr(0,0,0);

   unsigned long fPitch = fImage->GetPitch(); 
   unsigned long Width = fImage->GetWidth();
   unsigned long Height = fImage->GetHeight();

   ipByteAoi gray(1); 
   gray.Create(Width,Height,0);

   unsigned char* pGray = gray.GetPixAdr(0,0,0);


   for(int yy =0; yy < Height; yy++)
   {
	   for(int xx = 0; xx < Width; xx++)
	   {
			*(pGray + yy*fPitch + xx) = ( (float)(*(pfImageR + yy*fPitch + xx)) * (0.299) + 
										  (float)(*(pfImageG + yy*fPitch + xx)) * (0.587) +
										  (float)(*(pfImageB + yy*fPitch + xx)) * (0.114) ); 
	   
	   }
   }

   ipWritePPM(gray,"grayscale.pgm");

   ipByteAoi histo(1);
   histo.Create(256,400,0);

   unsigned char* histoAdr = histo.GetPixAdr(0,0,0);
   unsigned long histoPitch = histo.GetPitch();

   int* arr = new int[256];
   for(int m = 0; m < 256; m++)
	   arr[m] = 0; 
   int max = 0; 

   
   for(int yy = 490; yy < 560; yy++)
   {
	   for(int xx = 670; xx < 760; xx++)
	   {
			arr[*(pGray + yy*fPitch + xx)]++; 
			if(arr[*(pGray + yy*fPitch +xx)] > max)
				max = arr[*(pGray + yy*fPitch + xx)];
	   }
   }


   for(int s = 0; s < 256; s++)
   {
	   arr[s] = ((float)arr[s] / max) * 400; 
	   cout << "arr[" << s <<"]: " << arr[s] << endl;
   }
   cout << "max: " << max << endl;
   for(int y = 0; y < 400; y++)
   {
	   for(int x = 0; x < 256; x++)
	   {
		   if( (400 - y) < arr[x])
			*(histoAdr + y*histoPitch + x) = 0;
		   else
			*(histoAdr + y*histoPitch + x) = 255;
	   }
   }

   ipWritePPM(histo,"histogram.pgm");
   delete[] arr;

   unsigned long Width2 = 90; 
   unsigned long Height2 = 200;
   int* arr2 = new int[Width2];
   for(int m = 0; m< 90; m++)
	   arr2[m] = 0; 

   int max2 = 0; 

   ipByteAoi histo2(1);
   histo2.Create(90,400,0);
   unsigned char* histoAdr2 = histo2.GetPixAdr(0,0,0);
   unsigned long histoPitch2 = histo2.GetPitch();

   for(int x = 670; x < 760; x++)
   {
		for(int y = 490; y < 560; y++)
		{
			arr2[x-670] += *(pGray + y*fPitch + x);
			if(arr2[x-670] > max2)
				max2 = arr2[x-670]; 
		}
	}

   for(int s = 0; s < 90; s++)
   {
	   arr2[s] = ((float)arr2[s] / max2) * 400; 
	   cout << "arr2[" << s <<"]: " << arr2[s] << endl;
   }
  for(int y = 1; y<= 400; y++)
   {
		for(int x = 0; x < 90; x++)
		{
			if( (400 - y) < arr2[x])
			*(histoAdr2 + (400-y)*histoPitch2 + x) = 255;
		   else
			*(histoAdr2 + (400-y)*histoPitch2 + x) = 0;
		}
   }

   ipWritePPM(histo2,"histo_sum.pgm");


   delete[] arr2;
}

FaceReg::FaceReg(void)
{}

FaceReg::~FaceReg(void)
{}

⌨️ 快捷键说明

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