如何培养一个支持向量机(SVM)分类与OpenCV的面部特征? [英] How to train a Support Vector Machine(svm) classifier with openCV with facial features?

查看:291
本文介绍了如何培养一个支持向量机(SVM)分类与OpenCV的面部特征?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用面部前pression检测SVM分类。我知道OpenCV的一个SVM API,但是我不知道什么应该是训练分类输入。我看了很多文章到现在为止,所有的人都表示,以后面部特征检测训练分类。

I want to use the svm classifier for facial expression detection. I know opencv has a svm api, but I have no clue what should be the input to train the classifier. I have read many papers till now, all of them says after facial feature detection train the classifier.

到目前为止我做什么,


  1. 人脸检测,

  2. 16分的面部计算每一帧。下面是面部特征检测的输出![进入图像描述

  3. 持有特征点象素地址一个vector

注:我知道我可以只用正面和负面的形象训练SVM,我看到这个code <一个href=\"https://github.com/MasteringOpenCV/$c$c/blob/master/Chapter5_NumberPlateRecognition/trainSVM.cpp\">here,但我不知道我是如何与它相结合的面部特征信息。

Note: I know how I can train the SVM only with positive and negative images, I saw this codehere, But I don't know how I combine the facial feature information with it.

任何人可以帮我开始与SVM分类。

Can anybody please help me to start the classification with svm.

一个。应该是什么样的输入训练分类?

a. what should be the sample input to train the classifier?

乙。我该如何与这个人脸特征点训练分类?

b. How do I train the classifier with this facial feature points?

问候,

推荐答案

在机器学习交易算法在OpenCV中都配有一个类似的界面。训练它,你传递一个N×M的垫offeatures(N行,均设有一排长度M)和用类的标签一个NX1垫。像这样的:

the machine learning algos in opencv all come with a similar interface. to train it, you pass a NxM Mat offeatures (N rows, each feature one row with length M) and a Nx1 Mat with the class-labels. like this:

//traindata      //trainlabels

f e a t u r e    1 
f e a t u r e    -1
f e a t u r e    1
f e a t u r e    1
f e a t u r e    -1

为prediction,你填补了垫有1行以同样的方式,它会返回predicted标签

for the prediction, you fill a Mat with 1 row in the same way, and it will return the predicted label

所以,让我们说,你的16张脸部点存储在一个向量,你会做这样的:

so, let's say, your 16 facial points are stored in a vector, you would do like:

Mat trainData; // start empty
Mat labels;

for all facial_point_vecs:
{
    for( size_t i=0; i<16; i++ )
    {
        trainData.push_back(point[i]);
    }
    labels.push_back(label); // 1 or -1
}
// now here comes the magic:
// reshape it, so it has N rows, each being a flat float, x,y,x,y,x,y,x,y... 32 element array
trainData = trainData.reshape(1, 16*2); // numpoints*2 for x,y

// we have to convert to float:
trainData.convertTo(trainData,CV_32F);

SVM svm; // params omitted for simplicity (but that's where the *real* work starts..)
svm.train( trainData, labels );


//later predict:
vector<Point> points;
Mat testData = Mat(points).reshape(1,32); // flattened to 1 row
testData.convertTo(testData ,CV_32F);
float p = svm.predict( testData );

这篇关于如何培养一个支持向量机(SVM)分类与OpenCV的面部特征?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆