Face detection CC ++ source code

xiaoxiao2021-03-06  75

The C / C source code for face detection has published the Mailing List of OpenCV, mainly to make some speed optimization for the code released by OpenCV 3.1, and solves the problem of memory leakage. The PAUL VIOLA used in this program (the paper "Rapid Object Detection Using A Boosted Cascade Of Simple Features" ADA BOOSTED CASCADE algorithm in CVPR'01) can be said to be the fastest target detection algorithm.

About OpenCV, reference:

Http://blog.9cbs.net/hunnish/archive/2004/09/13/102535.aspx

For details on this algorithm, you can also refer to:

Http://www.merl.com/people/viola/research/publications/cvpr-2001.pdf

as well as:

http://www.assuredigit.com/forum/display_topic_threads.asp?forumid=11&topicid=325

http://www.assuredigit.com/forum/display_topic_threads.asp?forumid=11&topicid=463

Run file download:

Http://www.assuredigit.com/product_tech/demo_download_files/face.exe

This program can perform Face Tracking on still images and video sequences. For video sequences, please insert the camera of the USB interface first.

====

In the OpenCV version 3.1, compilation under VC6.0

====

=== # IFDEF _CH_ # define win32 # error "The File Needs CVAUX, Which is not warapped yet. sorry" #ENDIF

#ifndef _eic # include "cv.h" #include "cvaux.h" #include "highgui.h"

#ENDIF

#ifdef _eic # define win32 # Endif

#define orig_win_size 24static cvmemstorage * storage = 0; static cvhidhaarclassifiercascade * hid_cascade = 0;

#define WinName "Result"

Void detect_and_draw (iPlimage * Image, iPlimage * Tempimage);

INT Main (int Argc, char ** argv) {cvcapture * capture = 0;

Cvhaarclassifiercascade * cascade = CVLOADHAARCLASSIFIERCASCADE ("

"

CVSIZE (Orig_Win_Size, Orig_WIN_SIZE));

HID_CASCADE = CvcreateHidhaarclassifierCascade (Cascade, 0, 0, 0, 1);

CVRELEASEHAARCLASSIFIERCASCADE (& cascade);

CvnamedWindow (WinName, 1); Storage = CvcreateMemStorage (0); if (argc == 1 || (argc == 2 && strlen (argv [1]) == 1 && isdigit (Argv [1] [0]))))) ) Capture = CVCaptureFromCam (argc == 2? Argv [1] [0] - '0': 0); Else IF (argc == 2) Capture = CVCaptureFromavi (argv [1]); if (Capture) {iPlimage * Frame, * Temp; Cvgrabframe (CAPTURE); FRAME = CVRETREVEFRAME (CAPTURE); TEMP = CVCReateImage (CVSIZE-> Width / 2, Frame-> Height / 2), 8, 3);

For (;;) {if (! cvgrabframe (capTure)) Break; frame = CVRETRIEVEFRAME (CAPTURE); if (! frame) Break;

Detect_and_draw (frame, temp);

if (cvWaitKey (10)> = 0) {// cvReleaseImage (& frame); // cvReleaseImage (& temp); cvReleaseCapture (& capture); cvDestroyWindow (WINNAME); return 0;}}} else {char * filename = argc == 2? Argv [1]: (char *) "lena.jpg"; iPlimage * Image = CVLoadImage (filename, 1); iPlimage * Temp = CVCReateImage (cvsize (image-> width / 2, Image-> height / 2) , 8, 3);

if (image) {cvFlip (image, image, 0); image-> origin = IPL_ORIGIN_BL; detect_and_draw (image, temp); cvWaitKey (0); cvReleaseImage (& image); cvReleaseImage (& temp);} cvDestroyWindow (WINNAME); return 0;} Return 0;}

void detect_and_draw (IplImage * img, IplImage * temp) {int scale = 2; CvPoint pt1, pt2; int i; cvPyrDown (img, temp, CV_GAUSSIAN_5x5); # ifdef WIN32 cvFlip (temp, temp, 0); # endif cvClearMemStorage ( STORAGE);

IF (hid_cascade) {CVSEQ * Faces = CVhaardteTectObjects (Temp, Hid_cascade, Storage, 1.2, 2, CV_haar_do_canny_pruning); for (i = 0; i <(Faces? Faces-> Total: 0); i ) {CVRECT * R = (CVRect *) CvgetSeqlem (Faces, I, 0); Pt1.x = r-> x * scale; pt2.x = (r-> x r-> width) * scale; #ifdef Win32 Pt1.y = img -> Height - r-> y * scale; pt2.y = img-> height - (r-> y r-> height) * scale; #else pt1.y = r-> y * scale; pt2.y = (r-> y r-> height) * scale; #ENDIF CVRectangle (IMG, PT1, PT2, CV_RGB (255, 255, 0), 3);}}

CvShowImage (WinName, IMG); // CVRELEASEIMAGE (& TEMP);

#ifdef _eicmain (1, "facedetect.c"); # ENDIF

转载请注明原文地址:https://www.9cbs.com/read-120941.html

New Post(0)