Face Detection and Recognition System Based on QT and opencv (1)

Source: Internet
Author: User

Face recognition is divided into two steps

1. Face detection is the first implementation. You need to frame the face when displaying the face. Of course, there are many algorithms, and there are some human eyes that can detect the nose.

This is mainly used

Const char * facecascadefilename = "haarcascade_frontalface_alt.xml ";

Detect_and_draw (iplimagebuffer, storage, cascade );

This function is used to detect faces and draw frames as follows:

The main code is as follows:

Void chenaini: detect_and_draw (iplimage * IMG, cvmemstorage * storage, cvhaarclassifiercascade * cascade)
{
Double scale = 1.2;
Static cvscalar colors [] = {
{0, 0, 255 },{ {0,128,255 }}, {0,255,255 },{ 0,255, 0 }},
{255,128, 0 }},{ {255,255, 0 }},{ {255, 0 }}
}; // Just some pretty colors to draw


Iplimage * gray = cvcreateimage (cvsize (IMG-> width, IMG-> height), 8, 1 );
Iplimage * small_img = cvcreateimage (cvsize (cvround (IMG-> width/scale), cvround (IMG-> height/scale), 8, 1 );
Cvcvtcolor (IMG, gray, cv_bgr2gray );
Cvresize (Gray, small_img, cv_inter_linear );

Cvequalizehist (small_img, small_img); cvclearmemstorage (storage );
Double T = (double) cvgettickcount ();
Cvsize min = cvsize (0, 0 );
Cvsize max = cvsize (100,100 );
Cvseq * objects = cvhaardetectobjects (small_img,
Cascade, storage,
1.1,
3, 0/* cv_haar_do_canny_pruning */,
Min,
Max
);

T = (double) cvgettickcount ()-T;
Printf ("detection time = % GMS \ n", t/(double) cvgettickfrequency () * 1000 .));

// Loop through found objects and draw boxes around them
For (INT I = 0; I <(objects? Objects-> total: 0); ++ I)
{
Cvrect * r = (cvrect *) cvgetseqelem (objects, I );
Cvrectangle (IMG, cvpoint (R-> X * scale, R-> y * scale), cvpoint (R-> X + R-> width) * scale, (R-> Y + R-> height) * scale), colors [I % 8]);
}
For (INT I = 0; I <(objects? Objects-> total: 0); I ++)
{
Cvrect * r = (cvrect *) cvgetseqelem (objects, 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 );
}

Qimage image (uchar *) IMG-> imagedata, IMG-> width, IMG-> height, qimage: format_rgb888 );

UI-> label_shipin-> clear ();
UI-> label_shipin-> setscaledcontents (true );
UI-> label_shipin-> setpixmap (qpixmap: fromimage (image ));
Rs = VD-> unget_frame ();
Cvreleaseimage (& IMG );

}

 

 

Face Detection and Recognition System Based on QT and opencv (1)

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.