基于Gabor+PCA+SVM的性别识别(1)


基于Gabor+PCA+SVM的性别识别.图像预处理。从人脸数据库提取人脸。为提取特征做准备
资源截图
代码片段和文件信息
#include “opencv2/opencv.hpp“
#include “opencv2/imgproc/imgproc.hpp“
#include 
#include 

using namespace std;
using namespace cv;
int CropImageCount = 0; //裁剪出来的样本图片个数

string face_cascade_name =“D:\Program Files\opencv\sources\data\haarcascades\haarcascade_frontalface_alt.xml“;
CascadeClassifier face_cascade;
string window_name = “人脸识别“;

Mat detectAndDisplay( Mat);

int main()
{
    Mat imageROI;
    //image = imread(“pangzi.jpg“);

if( !face_cascade.load( face_cascade_name ) )
  { 
        printf(“[error] 无法加载级联分类器文件!
“);
        return -1; 
      }
string ImgName;
char saveName[256];  //裁剪出来的负样本图片文件名
ifstream fin(“woman.txt“);//打开原始样本图片文件列表
//ifstream fin(“woman.txt“);//打开原始样本图片文件列表
//一行一行读取文件列表
while(getline(finImgName))
{  
cout<<“处理:“< //ImgName = “D:\Mycode\man\“ + ImgName+“.png“;
ImgName = “D:\Mycode\woman\“ + ImgName+“.png“;
//cout< image= imread(ImgName);//读取图片

        if(image.data ==0)
   {
          printf(“[error] 没有图片
“);
          return -5;
       }
      ROI= detectAndDisplay(image);
  // cout< //sprintf(saveName“man%d.png“++CropImageCount);//生成裁剪出的样本图片的文件名
sprintf(saveName“woman%d.png“++CropImageCount);//生成裁剪出的样本图片的文件名
imwrite(saveName ROI);//保存文件
 }
    waitKey(0); 
return 4;
}

Mat detectAndDisplay( Mat frame)
{
    std::vector faces;
    Mat frame_grayROI;
frame_gray= frame;
    cvtColor( frame frame_gray CV_BGR2GRAY );
    equalizeHist( frame_gray frame_gray );

    face_cascade.detectMultiScale( frame_gray faces 1.1 2 0|CV_HAAR_SCALE_IMAGE Size(30 30) );

    for( int i = 0; i < faces.size(); i++ )
{
        Point center( faces[i].x + faces[i].width*0.5 faces[i].y + faces[i].height*0.5 );
       // ellipse( frame center Size( faces[i].width*0.5 faces[i].height*0.5) 0 0 360 Scalar( 255 0 255 ) 4 8 0 );
     rectangle(frame                //图像.
     faces[i].tl()             //矩形的一个顶点。
 faces[i].br()             //矩形对角线上的另一个顶点
 Scalar(0 255 0)  //线条颜色 (RGB) 或亮度(灰度图像 )(grayscale image)
  3);                 //组成矩形的线条的粗细程度。取负值时(如 CV_FILLED)函数绘制填充了色彩的矩形
     ROI=frame_gray(Rect(faces[i].tl().xfaces[i].tl().yfaces[i].widthfaces[i].height));
 resize(ROIROISize(2118)00CV_INTER_LINEAR);
}
//namedWindow(“qq“2);
//imshow( “qq“ ROI );
   
 // imshow( window_name frame );
return ROI;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     107520  2015-12-26 17:08  face_cutDebugface_cut.exe

     文件    1179576  2015-12-26 17:08  face_cutDebugface_cut.ilk

     文件    1911808  2015-12-26 17:08  face_cutDebugface_cut.pdb

     文件     175113  2015-12-13 19:37  face_cutface_cutDebugBrowseDir.obj

     文件       5222  2015-12-26 17:08  face_cutface_cutDebugcl.command.1.tlog

     文件      99568  2015-12-26 17:08  face_cutface_cutDebugCL.read.1.tlog

     文件       3404  2015-12-26 17:08  face_cutface_cutDebugCL.write.1.tlog

     文件     445019  2015-12-13 19:37  face_cutface_cutDebugdetect.obj

     文件     229362  2015-12-13 19:37  face_cutface_cutDebugdetection.obj

     文件        406  2015-12-14 10:21  face_cutface_cutDebugface_cut.exe.embed.manifest

     文件        472  2015-12-14 10:21  face_cutface_cutDebugface_cut.exe.embed.manifest.res

     文件        381  2015-12-26 17:08  face_cutface_cutDebugface_cut.exe.intermediate.manifest

     文件         57  2015-12-26 17:08  face_cutface_cutDebugface_cut.lastbuildstate

     文件       3354  2015-12-26 17:08  face_cutface_cutDebugface_cut.log

     文件        713  2015-12-13 19:37  face_cutface_cutDebugface_cut.vcxprojResolveAssemblyReference.cache

     文件          0  2015-12-13 19:37  face_cutface_cutDebugface_cut.write.1.tlog

     文件        206  2015-12-13 19:46  face_cutface_cutDebugface_cut_manifest.rc

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink-cvtres.read.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink-cvtres.write.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1048-cvtres.read.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1048-cvtres.write.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1048.read.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1048.write.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1600-cvtres.read.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1600-cvtres.write.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1600.read.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1600.write.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1740-cvtres.read.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1740-cvtres.write.1.tlog

     文件          2  2015-12-26 17:08  face_cutface_cutDebuglink.1740.read.1.tlog

............此处省略103个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)