openCV中的人脸识别API
2015-06-25 19:50
429 查看
本文转自:/article/2313264.html
1.建立人脸识别器
createEigenFaceRecognizer
C++: Ptr<FaceRecognizer> createEigenFaceRecognizer(intnum_components=0, double threshold=DBL_MAX)¶
createFisherFaceRecognizer
C++: Ptr<FaceRecognizer>
createFisherFaceRecognizer(intnum_components=0, double
threshold=DBL_MAX)
createLBPHFaceRecognizer
C++: Ptr<FaceRecognizer>
createLBPHFaceRecognizer(int
radius=1, int neighbors=8, int grid_x=8, intgrid_y=8, double
threshold=DBL_MAX)
2.训练
C++: void
FaceRecognizer::train(InputArrayOfArrayssrc, InputArray
labels) = 0¶
3.预测
C++: int FaceRecognizer::predict(InputArraysrc)
const = 0¶
C++: void FaceRecognizer::predict(InputArraysrc, int&
label, double& confidence) const = 0¶
Predicts a label and associated confidence (e.g. distance) for a given input image.
简单应用:
[cpp]
view plaincopyprint?
int FR::FR_LBPH()
{
if(trainImages.size()<=0)
{
cout<<"please read train data first!"<<endl;
return 1;
}
Ptr<FaceRecognizer> model=createLBPHFaceRecognizer(2,8,10,14);
model->train(trainImages,trainLabels);
int plabel= -1;
double predicted_confidence = 0.0;
double correct=0;
for(int i=0;i<testImages.size();i++)
{
model->predict(testImages[i],plabel,predicted_confidence);
if(plabel==testLabels[i])
{
correct++;
}
else
{
cout<<"name:"<<testNames[i]<<" label:"<<testLabels[i]<<" plabel:"<<plabel<<endl;
}
}
cout<<correct/testImages.size()<<endl;
return 0;
}
注意:包含头文件#include "opencv2/contrib/contrib.hpp"
本文转自:/article/2313264.html
1.建立人脸识别器
createEigenFaceRecognizer
C++: Ptr<FaceRecognizer> createEigenFaceRecognizer(intnum_components=0, double threshold=DBL_MAX)¶
Parameters: | num_components – The number of components (read: Eigenfaces) kept for this Prinicpal Component Analysis. As a hint: There’s no rule how many components (read: Eigenfaces) should be kept for good reconstruction capabilities. It is based on your input data, so experiment with the number. Keeping 80 components should almost always be sufficient. threshold – The threshold applied in the prediciton. |
---|
C++: Ptr<FaceRecognizer>
createFisherFaceRecognizer(intnum_components=0, double
threshold=DBL_MAX)
Parameters: | num_components – The number of components (read: Fisherfaces) kept for this Linear Discriminant Analysis with the Fisherfaces criterion. It’s useful to keep all components, that means the number of your classesc (read: subjects, persons you want to recognize). If you leave this at the default (0) or set it to a value less-equal0 or greater (c-1), it will be set to the correct number (c-1) automatically. threshold – The threshold applied in the prediction. If the distance to the nearest neighbor is larger than the threshold, this method returns -1. |
---|
C++: Ptr<FaceRecognizer>
createLBPHFaceRecognizer(int
radius=1, int neighbors=8, int grid_x=8, intgrid_y=8, double
threshold=DBL_MAX)
Parameters: | radius – The radius used for building the Circular Local Binary Pattern. The greater the radius, the neighbors – The number of sample points to build a Circular Local Binary Pattern from. An appropriate value is to use `` 8`` sample points. Keep in mind: the more sample points you include, the higher the computational cost. grid_x – The number of cells in the horizontal direction, 8 is a common value used in publications. The more cells, the finer the grid, the higher the dimensionality of the resulting feature vector. grid_y – The number of cells in the vertical direction, 8 is a common value used in publications. The more cells, the finer the grid, the higher the dimensionality of the resulting feature vector. threshold – The threshold applied in the prediction. If the distance to the nearest neighbor is larger than the threshold, this method returns -1. |
---|
C++: void
FaceRecognizer::train(InputArrayOfArrayssrc, InputArray
labels) = 0¶
Parameters: | src – The training images, that means the faces you want to learn. The data has to be given as avector<Mat>. labels – The labels corresponding to the images have to be given either as avector<int> or a |
---|
C++: int FaceRecognizer::predict(InputArraysrc)
const = 0¶
C++: void FaceRecognizer::predict(InputArraysrc, int&
label, double& confidence) const = 0¶
Predicts a label and associated confidence (e.g. distance) for a given input image.
Parameters: | src – Sample image to get a prediction from. label – The predicted label for the given image. confidence – Associated confidence (e.g. distance) for the predicted label. |
---|
[cpp]
view plaincopyprint?
int FR::FR_LBPH()
{
if(trainImages.size()<=0)
{
cout<<"please read train data first!"<<endl;
return 1;
}
Ptr<FaceRecognizer> model=createLBPHFaceRecognizer(2,8,10,14);
model->train(trainImages,trainLabels);
int plabel= -1;
double predicted_confidence = 0.0;
double correct=0;
for(int i=0;i<testImages.size();i++)
{
model->predict(testImages[i],plabel,predicted_confidence);
if(plabel==testLabels[i])
{
correct++;
}
else
{
cout<<"name:"<<testNames[i]<<" label:"<<testLabels[i]<<" plabel:"<<plabel<<endl;
}
}
cout<<correct/testImages.size()<<endl;
return 0;
}
int FR::FR_LBPH() { if(trainImages.size()<=0) { cout<<"please read train data first!"<<endl; return 1; } Ptr<FaceRecognizer> model=createLBPHFaceRecognizer(2,8,10,14); model->train(trainImages,trainLabels); int plabel= -1; double predicted_confidence = 0.0; double correct=0; for(int i=0;i<testImages.size();i++) { model->predict(testImages[i],plabel,predicted_confidence); if(plabel==testLabels[i]) { correct++; } else { cout<<"name:"<<testNames[i]<<" label:"<<testLabels[i]<<" plabel:"<<plabel<<endl; } } cout<<correct/testImages.size()<<endl; return 0; }
注意:包含头文件#include "opencv2/contrib/contrib.hpp"
相关文章推荐
- CentOS 7 更新软件源和系统
- Apache重启报错原因
- Linux mkdir 命令
- linux下实现ls()函数遍历目录
- [LINUX]OPENSUSE登录界面密码
- nginx 反向代理 golang web
- Linux mkdir 命令
- [linux]suse 安装输入法
- Xdmcp 服务的启用 问题(鸟哥的Linux私房菜 问题)
- 如何修改和查看tomcat内存大小
- xshell十大技巧
- 部队->运维->分享->讲师历程
- MapReduce中作业调度器
- mac上jdk1.8换1.7 eclipse tomcat
- nginx虚拟机配置(支持php)
- nginx 内存池
- poj 2186 Popular Cows(targan算法)
- 建立LINUX服务器
- linux 添加、删除硬盘 mount/unmount
- 《linux备份与恢复之一》.tar.bz2与.tar.gz格式的文本压缩率比较