#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
#ifdef _EiC
#define WIN32
#endif
static CvMemStorage* storage = 0;
static CvHaarClassifierCascade* cascade = 0;
time_t timeBegin, timeEnd;
int timeuse;
void detect_and_draw( IplImage* image );
int main( int argc, char** argv )
{
CvCapture* capture = 0;
IplImage *frame, *frame_copy = 0;
int optlen = strlen("--cascade=");
char *cascade_name = "H://opencv-2.4.3//opencv//data//haarcascades//haarcascade_frontalface_alt2.xml";
//opencv装好后haarcascade_frontalface_alt2.xml的路径,
//也可以把这个文件拷到你的工程文件夹下然后不用写路径名cascade_name= "haarcascade_frontalface_alt2.xml";
//或者cascade_name ="C:\\Program Files\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt2.xml"
cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
if( !cascade )
{
fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
fprintf( stderr,
"Usage: facedetect --cascade=\"<cascade_path>\" [filename|camera_index]\n" );
return -1;
}
storage = cvCreateMemStorage(0);
capture = cvCaptureFromCAM(-1);
cvNamedWindow( "result", 1 );
if( capture )
{
timeBegin = time(NULL);
for(;;)
{
timeEnd = time(NULL);
timeuse=timeEnd - timeBegin;//计算经过的时间,每隔2s拍摄一张照片
if( !cvGrabFrame( capture ))
break;
frame =
opencv中image detection中截取人脸图片为大小统一的照片作为识别的模版
最新推荐文章于 2023-04-26 09:35:08 发布
该程序使用OpenCV库实现从摄像头捕获的人脸检测,通过CvHaarClassifierCascade分类器识别人脸,并在检测到人脸的2秒间隔内将其截取并保存为大小统一的.jpg图片。程序涉及了图像预处理、人脸检测和图片保存等步骤。
摘要由CSDN通过智能技术生成