OPENCV detecting human Face instance code

Source: Internet
Author: User

Here is the code that uses OPENCV to Haar face detection by reading the image on the hard disk.
Include header file
#include <opencv2/core/core.hpp>
#include "Cv.h"
#include "highgui.h"

int main ()
{
Const char* Cascade_name = "c:\\opencv249\\sources\\data\\haarcascades\\haarcascade_frontalface_alt2.xml";//classifier path, According to the actual fill

Static cvmemstorage* storage = 0;
static cvhaarclassifiercascade* cascade = 0;

Cascade = (cvhaarclassifiercascade*) cvload (cascade_name, 0, 0, 0);
Storage = cvcreatememstorage (0);

Iplimage *image = cvloadimage ("e:\\1.jpg");//read in the image, press the actual input

Cvseq* faces = cvhaardetectobjects (image, Cascade, storage, 1.1, 2, cv_haar_do_canny_pruning, cvsize (+));//haar Face Detection

int num_of_face = faces->total;//The number of faces that were detected

Cvscalar Color[1] = {255, 0, 0};//set Rectangle box color

for (int i = 1; i < Num_of_face + 1; i++)
{
cvrect* r = (cvrect*) Cvgetseqelem (faces, i); Gets the information for each face, the return type is a rectangle. I for face number, 0,1,2 ... Can be read in a loop.
Cvrectangle (Image, Cvpoint (r->x, R->y), Cvpoint (r->x + r->width, R->y + r->height), color[0], 3);// Draw a rectangular box
}

Cvnamedwindow ("Test", cv_window_autosize);//Create window, the second parameter cv_window_autosize represents the original size of the saved image
Cvshowimage ("Test", image);//Display picture

Cvwaitkey (0);//wait for operation

Cvreleaseimage (&image);//Release picture
Cvdestroywindow ("Test");//Destroy Window

return 0;
}
OPENCV-based face detection and save picture send: http://www.eyesourcecode.com/thread-41275-1-1.html
OpenCV Source: http://www.eyesourcecode.com/forum-OpenCV-1.html

OPENCV detecting human Face instance code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.