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

📄 haarcascade.cpp

📁 OpenCV的各类例子
💻 CPP
字号:
#include "cv.h"#include "highgui.h"CvHaarClassifierCascade* load_object_detector( const char* cascade_path ){    return (CvHaarClassifierCascade*)cvLoad( cascade_path );}void detect_and_draw_objects( IplImage* image,                              CvHaarClassifierCascade* cascade,                              int do_pyramids ){    IplImage* small_image = image;    CvMemStorage* storage = cvCreateMemStorage(0);    CvSeq* faces;    int i, scale = 1;    /* if the flag is specified, down-scale the 输入图像 to get a       performance boost w/o loosing quality (perhaps) */    if( do_pyramids )    {        small_image = cvCreateImage( cvSize(image->width/2,image->height/2), IPL_DEPTH_8U, 3 );        cvPyrDown( image, small_image, CV_GAUSSIAN_5x5 );        scale = 2;    }    /* use the fastest variant */faces = cvHaarDetectObjects( small_image, cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING );    /* draw all the rectangles */    for( i = 0; i < faces->total; i++ )    {        /* extract the rectanlges only */        CvRect face_rect = *(CvRect*)cvGetSeqElem( faces, i );        cvRectangle( image, cvPoint(face_rect.x*scale,face_rect.y*scale),                     cvPoint((face_rect.x+face_rect.width)*scale,                             (face_rect.y+face_rect.height)*scale),                     CV_RGB(255,0,0), 3 );    }    if( small_image != image )        cvReleaseImage( &small_image );    cvReleaseMemStorage( &storage );}/* takes image filename and cascade path from the command line */int main( int argc, char** argv ){    IplImage* image;    if( argc==3 && (image = cvLoadImage( argv[1], 1 )) != 0 )    {        CvHaarClassifierCascade* cascade = load_object_detector(argv[2]);        detect_and_draw_objects( image, cascade, 1 );        cvNamedWindow( "test", 0 );        cvShowImage( "test", image );        cvWaitKey(0);        cvReleaseHaarClassifierCascade( &cascade );        cvReleaseImage( &image );    }    return 0;}

⌨️ 快捷键说明

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