Gender identification based on GABOR+PCA+SVM (3) (end)

Source: Internet
Author: User
Tags svm

Welcome reprint, please indicate the source, I have limited ability, mistakes are unavoidable, welcome to guide

Based on the first two posts, a sex classifier has been trained. Then this classifier should be used for gender classification.

This test process is the same as the training process. However, during training, the sample data is processed in large quantities. The test process is processed for images that need to be identified.

    1. First, face recognition, that is, in the image to find the face, the face area extracted.
    2. In the second step, we use Gabor wavelet to extract the features of human face.
    3. In the third step, we use PCA to reduce the dimension of Gabor extraction features.
    4. Finally, the post-dimensionality feature is inputted and the classifier is trained to obtain the classification result.

The results show:

Results Analysis:

Training Process Man sample 409,woman sample 287. In fact, for machine learning, these samples are still very small. When testing, 6 man images can be correctly identified. The woman image recognition process has been incorrectly identified. Because the sample pictures are foreigners, and the number is limited. The effect on other pictures should not be very good.

The main reasons for my analysis are two points: 1) in the training process, the parameters selection of Gabor wavelet and PCA reduction process are not strictly tested.

2) There are too few training samples, and the sample has a few faces. You can increase the number of training samples.

Finally, we have to mention that the training process is computationally large. Training more than 600 samples, run it should be half an hour.

Main.cpp (Gabor files same as (2))

1#include <opencv2/opencv.hpp>2#include <opencv2/highgui/highgui.hpp>3#include <opencv2/ml/ml.hpp>4#include"GaborFR.h"5 using namespaceCV;6 using namespacestd;7 Mat Detectanddisplay (MAT);8 //load OPENCV with Face recognition cascade classifier file9 stringFace_cascade_name ="D:\\Program Files\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt.xml";Ten cascadeclassifier Face_cascade; One intIsize=Ten;//the scale of Gabor A intMain () - {   -     if( !face_cascade.load (face_cascade_name)) the       {  -printf"[ERROR] could not load cascading classifier file! \ n"); -         return-1;  -       } +  -Mat Testi = Imread ("Man5.png"); +     if(Testi.data = =0) A        { atprintf"[ERROR] no picture \ n"); -           return-5; -        } -     //extract face *****************************************************. -Mat roi=Detectanddisplay (testi); -     //Gabor transform ************************************************************* inNormalize (Roi,roi,1,0, cv_minmax,cv_32f); - Mat Feature_gabor; to feature_gabor.release (); +        for(intI=0;i<8; i++) -     { the          *          for(intj=0;j<5; j + +) $         {Panax NotoginsengMat m1=Gaborfr::getrealgaborkernel (Size (isize,isize), -                                                  2*Cv_pi, thei*cv_pi/8+cv_pi/2, + J, A                                                  1); theMat M2 =Gaborfr::getimaggaborkernel (Size (isize,isize), +                                                  2*Cv_pi, -i*cv_pi/8+cv_pi/2, $ J, $                                                  1); -             //add CV_PI/2 and most of the literature, like the graphics, do not know why!  - Mat Outr,outi; the Gaborfr::getfilterrealimagpart (Roi,m1,m2,outr,outi); -Mat m_magnitude=gaborfr::getmagnitude (Outr,outi);WuyiNormalize (M_magnitude,m_magnitude,0,1, cv_minmax,cv_32f); theMat line= M_magnitude.reshape (0,1); - Feature_gabor.push_back (line); Wu     -         } About     } $  - //PCA Reduced Dimension ************************************************** -PCA PCA (Feature_gabor, Cv::mat (), Cv_pca_data_as_row,5); -Mat dst=Pca.project (Feature_gabor); AMat Line =dst.reshape (0,1); +  the //SVM for gender identification ************** - CVSVM MYSVM; $Mysvm.load ("Svm_pca4.xml");//Read the trained SVM classifier model from XML file the     floatResponse =mysvm.predict (line); the  thecout<< response<<Endl; the     if(response==1) -cout<<" Boy"<<Endl; in     if(response==-1) thecout<<"Girl"<<Endl; theWaitkey (0); AboutSystem"Pause"); the } the  the  + Mat Detectanddisplay (Mat frame) - { theStd::vector<rect>faces;Bayi Mat Frame_gray,roi; theframe_gray=frame; the Cvtcolor (frame, frame_gray, cv_bgr2gray); - equalizehist (Frame_gray, frame_gray); -  theFace_cascade.detectmultiscale (Frame_gray, Faces,1.1,2,0| Cv_haar_scale_image, Size ( -, -) ); the      the      for(inti =0; I < faces.size (); i++ ) the     { -Point Center (faces[i].x + faces[i].width*0.5, Faces[i].y + faces[i].height*0.5 ); the        //ellipse (frame, center, Size (faces[i].width*0.5, faces[i].height*0.5), 0, 0,, Scalar (255, 0, 255), 4, 8, 0); /c3> theRectangle (Frame,//image. theFACES[I].TL (),//a vertex of the rectangle. 94faces[i].br (),//another vertex on the diagonal of the rectangle theScalar (0,255,0),//Line Color (RGB) or luminance (grayscale images) (grayscale image) the                   3);//The thickness of the line that makes up the rectangle. A negative value (such as the cv_filled) function draws a color-filled rectangle theRoi=Frame_gray (Rect (faces[i].tl (). X,FACES[I].TL (). y,faces[i].width,faces[i].height));98Resize (Roi,roi,size ( +, -),0,0, cv_inter_linear); About     } -     101     //Namedwindow ("QQ", 2);102     //imshow ("QQ", ROI);103    104Imshow ("Window_name", frame); the     returnROI;106}

Gender identification based on GABOR+PCA+SVM (3) (end)

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.