我目前正在处理一个项目,需要从网络摄像头中提取用户的面部表情(仅限单个用户),例如悲伤或快乐。
我用以下方法对面部表情进行分类:
我将如何使用这些特征点为每种情感训练SVM?
我用以下方法对面部表情进行分类:
- 使用opencv检测图像中的脸
- 使用ASM和stasm获取面部特征点
我将如何使用这些特征点为每种情感训练SVM?
import numpy as np
import cv2
samples = np.array(np.random.random((4,5)), dtype = np.float32)
labels = np.array(np.random.randint(0,2,4), dtype = np.float32)
svm = cv2.SVM()
svmparams = dict( kernel_type = cv2.SVM_LINEAR,
svm_type = cv2.SVM_C_SVC,
C = 1 )
svm.train(samples, labels, params = svmparams)
testresult = np.float32( [svm.predict(s) for s in samples])
print samples
print labels
print testresult
svm.save('model.xml')
loaded=svm.load('model.xml')
和输出
#print samples
[[ 0.24686454 0.07454421 0.90043277 0.37529686 0.34437731]
[ 0.41088378 0.79261768 0.46119651 0.50203663 0.64999193]
[ 0.11879266 0.6869216 0.4808321 0.6477254 0.16334397]
[ 0.02145131 0.51843268 0.74307418 0.90667248 0.07163303]]
#print labels
[ 0. 1. 1. 0.]
#print testresult
[ 0. 1. 1. 0.]
https://github.com/lisa-lab/DeepLearningTutorials/
http://www.codeproject.com/Articles/16650/Neural-Network-for-Recognition-of-Handwritten-Digi
-编辑-
地标只是n个(x,y)向量,对吧?那么为什么不把它们放入一个大小为2n的数组中,然后直接将它们馈送到上面的代码中呢?
例如,4个地标的3个训练样本(0,0),(10,10),(50,50),(70,70)
samples = [[0,0,10,10,50,50,70,70],
[0,0,10,10,50,50,70,70],
[0,0,10,10,50,50,70,70]]
labels=[0.,1.,2.]
0=高兴
1=生气
2=厌恶