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

📄 facef.cpp

📁 这是个人脸识别程序
💻 CPP
字号:
// $util\facef.cpp 1.5 milbo$ find faces using the Viola Jones or Rowley detector//-----------------------------------------------------------------------------// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// A copy of the GNU General Public License is available at// http://www.r-project.org/Licenses///-----------------------------------------------------------------------------#include "all.hpp"//-----------------------------------------------------------------------------intmain (int argc, const char *argv[]){Init(VERBOSE, FALSE, "log");					// open log file etc.// get data directory, it will be needed to locate data fileschar sBaseDir[SLEN], sDataDir[SLEN];_splitpath(argv[0], NULL, sBaseDir, NULL, NULL);if(sBaseDir == NULL || sBaseDir[0] == 0)    strcpy(sDataDir, "../../stasm/stasm/data");else    sprintf(sDataDir, "%s/../stasm/data", sBaseDir);bool fViolaJones = false;bool fViolaJonesEyes = false;static const char *sUsage = "Usage: facef [FLAGS] ImageFile [ImageFile2 ...]\n"    "\n"    "FLAGS:\n"    "-v  use the Viola Jones face detector (default is the Rowley detector)\n"    "-ve use the Viola Jones face detector and Rowley eye positions\n";while (--argc > 0 && (*++argv)[0] == '-')    {    switch (*(*argv + 1))        {#if _MSC_VER        case 'v':            fViolaJones = true;		    if (*(*argv + 2) == 'e')            	fViolaJonesEyes = true;            break;#endif        default:            Err(sUsage);        }    }if (argc < 1)    Err(sUsage);for (int iImage = 0; iImage < argc; iImage++)   // for each file on the cmd line    {    const char *sImageFile = argv[iImage];    lprintf("Processing %s ", sImageFile);    RgbImage RgbImg(sImageFile);    Image Img(RgbImg);    char sImage[SLEN], s[SLEN];    _splitpath(sImageFile, NULL, NULL, sImage, NULL);	SHAPE Shape;	bool fSuccess = false;	bool fEyes = true;	if (fViolaJones)		{	    fSuccess = fViolaJonesFindFace(Shape, Img, sImageFile, sDataDir);		AdjustViolaJonesShape(Shape);		if (fSuccess && fViolaJonesEyes)			{			int xRightEye, yRightEye, xLeftEye, yLeftEye;			fEyes = false;			FindEyesGivenFace(&xRightEye, &yRightEye, &xLeftEye, &yLeftEye,				Shape, Img, "../../stasm/stasm/data");			Shape.dimKeep(4, 2);	// add two extra rows for the eyes			if (xRightEye != -1 && yRightEye != -1 && xLeftEye != -1 && yLeftEye != -1)				{				fEyes = true;				Shape(DETECTOR_LEye, VX) = xRightEye  - Img.width / 2;				Shape(DETECTOR_LEye, VY) = Img.height / 2 - yRightEye;				Shape(DETECTOR_REye, VX) = xLeftEye - Img.width / 2;				Shape(DETECTOR_REye, VY) = Img.height / 2 - yLeftEye;				}			}		}	else	    fSuccess = fRowleyFindFace(Shape, Img, sImageFile, sDataDir);	if (!fSuccess)		lprintf("no face\n", sImageFile);	else		{		const int width = RgbImg.width, height = RgbImg.height;		DrawShape(RgbImg, Shape, C_YELLOW, 1.0, IM_CONNECT_DOTS);		CropImageToShape(RgbImg, Shape);		sprintf(s, "out/results-%s-%s-%s.bmp", 			(fEyes? "": "noeyes"), (fViolaJones? "vj": "rowley"), sImage);		WriteBmp(RgbImg, s, VERBOSE);#if 0		// convert shape coords(with 0,0 at center of image) to standard image coords		Shape.col(VX) += width / 2;		Shape.col(VY) = height / 2 - Shape.col(VY);#endif		Shape.print("", "%-5.2f ");		}    }Shutdown();return 0;   // success}

⌨️ 快捷键说明

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