Face.h
上传用户:xiaoge123
上传日期:2022-08-05
资源大小:5794k
文件大小:3k
- #include "cv.h"
- #include "highgui.h"
- #include "cxcore.h"
- #include "stdafx.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>
- #define DEFAULT_CASCADE_NAME "C:\Program Files\OpenCV\data\haarcascades\haarcascade_frontalface_alt2.xml"
- #ifdef _EiC
- #define WIN32
- #endif
- //int detect_and_draw( IplImage* image ,CvHaarClassifierCascade* cascade);
- static CvMemStorage* storage = 0;
- static CvHaarClassifierCascade* cascade = 0;
- //static CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)cvLoad ( DEFAULT_CASCADE_NAME, 0, 0, 0 );
- //void detect_and_draw( IplImage* image );
- const char* cascade_name ="../debug/haarcascade_frontalface_alt2.xml";
- //cascade = (CvHaarClassifierCascade*)cvLoad (cascade_name, 0, 0, 0 );
- /* "haarcascade_profileface.xml";*/
- /*int detect_and_draw( IplImage* img,CvHaarClassifierCascade* cascade )
- {
- storage = cvCreateMemStorage(0);
- //AfxMessageBox("hi,you!");
- int scale = 1;
- IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );
- CvPoint pt1, pt2;
- int i,N=0;
-
- //cvPyrDown( img, temp, CV_GAUSSIAN_5x5 );
- cvClearMemStorage( storage );
- //cvEqualizeHist(small_img,small_img);
- //AfxMessageBox("3");
- //cvClearMemStorage( storage );
- //AfxMessageBox("4");
- if( cascade )
- {
- //AfxMessageBox("cascade Loaded!");
- CvSeq* faces = cvHaarDetectObjects( img, cascade, storage,
- 1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
- cvSize(40, 40));
- //AfxMessageBox("Wrong!");
- N=faces ? faces->total:0;
- for( i = 0; i < (faces ? faces->total : 0); i++ )
- {
- CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
- pt1.x = r->x*scale;
- pt2.x = (r->x+r->width)*scale;
- pt1.y = r->y*scale;
- pt2.y = (r->y+r->height)*scale;
- cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
- }
- }
- else
- {
- AfxMessageBox(cascade_name);
- }
-
-
- cvNamedWindow("result",1);
- cvShowImage( "result", img );
- return N;
- //cvDestroyWindow("result");
- //AfxMessageBox("4");
- //cvReleaseImage( &gray );
- //cvReleaseImage( &small_img );
- }*/
- //把IplImage转化为CBitmap类型
- HBITMAP Ipl2Bmp(IplImage *img)
- {
- HBITMAP hBitmap;
- hBitmap=CreateBitmap(img->width, img->height,img->nChannels*8, 1, NULL);
- SetBitmapBits(hBitmap, img->imageSize, img->imageData);
- return hBitmap;
- }