资源简介

基于opencv+vc6.0的人脸检测,算法是AdaBoost

资源截图

代码片段和文件信息

#include “cv.h“
#include “highgui.h“
#include 
#include 
#include 
#include 

static CvMemStorage* storage = 0;
static CvHaarClassifierCascade* cascade = 0;
const char*cascade_name = “haarcascade_frontalface_alt2.xml“;

void detect_and_draw( IplImage* image );

int main( int argc char** argv )
{
cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name 0 0 0 );
    storage = cvCreateMemStorage(0);

    cvNamedWindow( “result“ 1 );
    IplImage* image = cvLoadImage( “IMG_1241.JPG“ 1 );
        
    if( image )
    {
detect_and_draw( image );
}

    cvShowImage( “result“ image );
cvSaveImage(“result.bmp“image);
cvWaitKey(0);
cvReleaseImage( &image );
    cvDestroyWindow(“result“);
    return 0;
}

void detect_and_draw( IplImage* img )
{
    static CvScalar colors[] = 
    {
        {{00255}}
        {{0128255}}
        {{0255255}}
        {{02550}}
        {{2551280}}
        {{2552550}}
        {{25500}}
        {{2550255}}
    };

    double scale = 2;
    IplImage* gray = cvCreateImage( cvSize(img->widthimg->height) 8 1 );
    IplImage* small_img = cvCreateImage( cvSize( cvRound (img->width/scale)
    cvRound (img->height/scale))8 1 );
    int i;

    cvCvtColor( img gray CV_BGR2GRAY );
    cvResize( gray small_img CV_INTER_LINEAR );
    cvEqualizeHist( small_img small_img );
    cvClearMemStorage( storage );

    if( cascade )
    {
        double t = (double)cvGetTickCount();
        CvSeq* faces = cvHaarDetectobjects( small_img cascade storage
        1.1 2 0/*CV_HAAR_DO_CANNY_PRUNING*/
        cvSize(15 15) );

        for( i = 0; i < (faces ? faces->total : 0); i++ )
        {
            CvRect* r = (CvRect*)cvGetSeqElem( faces i );
            CvPoint center;
            int radius;
            center.x = cvRound((r->x + r->width*0.5)*scale);
            center.y = cvRound((r->y + r->height*0.5)*scale);
            radius = cvRound((r->width + r->height)*0.25*scale);
            cvCircle( img center radius colors[i%8] 3 8 0 );
        }
    }
  
    cvReleaseImage( &gray );
    cvReleaseImage( &small_img );


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     192576  2012-05-23 19:37  face-AdaBoost\Debug\face detection.exe

     文件     208992  2012-05-23 19:37  face-AdaBoost\Debug\face detection.ilk

     文件      18505  2012-05-23 19:37  face-AdaBoost\Debug\face detection.obj

     文件    4114900  2012-05-23 19:34  face-AdaBoost\Debug\face detection.pch

     文件     467968  2012-05-23 19:37  face-AdaBoost\Debug\face detection.pdb

     文件     164864  2012-05-23 19:37  face-AdaBoost\Debug\vc60.idb

     文件     102400  2012-05-23 19:37  face-AdaBoost\Debug\vc60.pdb

     文件       2234  2012-05-23 19:37  face-AdaBoost\face detection.cpp

     文件       4268  2012-04-06 09:31  face-AdaBoost\face detection.dsp

     文件        553  2012-04-06 09:23  face-AdaBoost\face detection.dsw

     文件      41984  2012-05-23 20:17  face-AdaBoost\face detection.ncb

     文件      48640  2012-05-23 20:17  face-AdaBoost\face detection.opt

     文件        851  2012-05-23 19:37  face-AdaBoost\face detection.plg

     文件     861012  2005-03-16 19:18  face-AdaBoost\haarcascade_frontalface_alt2.xml

     目录          0  2012-05-23 19:37  face-AdaBoost\Debug

     目录          0  2012-05-25 10:32  face-AdaBoost

----------- ---------  ---------- -----  ----

              6229747                    16


评论

共有 条评论