码迷,mamicode.com
首页 > 其他好文 > 详细

opencv3.0 FaceRecongnizer说明

时间:2016-05-13 04:29:55      阅读:1525      评论:0      收藏:0      [点我收藏+]

标签:

#include<algorithm>
using namespace std;
using namespace cv;
//所有人脸识别模块都是从FaceRecongizer抽象类继承而来
//所有三类识别算法都是实现了下列方法
class FaceRecognizer : public Algorithm
{
public:
    //! virtual destructor
    virtual ~FaceRecognizer() {}
    //虚析构函数,便于回收内存
    // Trains a FaceRecognizer.训练人脸识别器
    virtual void train(InputArray src, InputArray labels) = 0;
    /*
        训练时有两个参数必须要明确:InputArray src,输入的图片
                              InputArray labels,相应图片对应的标志
        这两个参数都是类似于数组的数据结构(可以使用vector或者纯数组),src与labels通过相同的下标联系起来
     */

    // Updates a FaceRecognizer.//更新识别器参数说明与train()一样
    virtual void update(InputArrayOfArrays src, InputArray labels);

    // Gets a prediction from a FaceRecognizer.//识别
    virtual int predict(InputArray src) const = 0;

    // Predicts the label and confidence for a given sample.
    virtual void predict(InputArray src, int &label, double &confidence) const = 0;//识别一组图的类别,同时给出置信度
    //注意以上两个函数在实际中按需使用

    // Serializes this object to a given filename.
    virtual void save(const String& filename) const;

    // Deserializes this object from a given filename.
    virtual void load(const String& filename);

    // Serializes this object to a given cv::FileStorage.
    virtual void save(FileStorage& fs) const = 0;

    // Deserializes this object from a given cv::FileStorage.
    virtual void load(const FileStorage& fs) = 0;

    // Sets additional string info for the label
    virtual void setLabelInfo(int label, const String& strInfo);
    //为标记添加其它说明信息
    // Gets string info by label
    virtual String getLabelInfo(int label);
    //得到标记的说明信息
    // Gets labels by string info
    virtual vector<int> getLabelsByString(const String& str);
};

详细说明:
1·使用train()来对一个给定的人脸图片集进行训练.

2·对一张给定的图片进行预测,要求图片是Mat数据类型

3·可以从XML文件或者YAML文件载入一个训练好的模型器

4·可以为一个标识label设定详细的说明信息(比如姓名),说明信息以string方式存储在内存。

5·有时候,我们可能希望判断一张图片是否属于一个人脸库。此时一个通用的解决方案就是我们

可对预测置信度设置一个阈值。当置信度大于这个阈值就认为属于人脸库,否则就拒绝

6·update()函数只对小波法(LBPH)有用。其它两种算法只能重新训练

7· `void FaceRecognizer::save(const String& filename) const`
功能说明:

    将训练好的结果保存成xml或者yaml格式文档供下次使用

参数: 
filename – 文件名


8·`
C++: void FaceRecognizer::load(const String& filename)
C++: void FaceRecognizer::load(const FileStorage& fs) = 0
`
载入已经保存好的模型

9·进行训练和预测的图片都必须要事先进行灰度处理,同时训练和预测的图片必须要是相同规模大小的

10·创建三种识别器的方法:
1·创建Eigen人脸识别器:
    `C++: Ptr<FaceRecognizer> createEigenFaceRecognizer(int  num_components=0, double threshold=DBL_MAX)`
参数: 

num_components – The number of components (read: Eigenfaces) kept for this Principal 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 prediction.


*此Eigen模型不支持更新update*

模型的中间结果:

num_components see createEigenFaceRecognizer().

threshold see createEigenFaceRecognizer().

eigenvalues 特征值(降序).

eigenvectors特征向量(与对应的特征值同序).

mean 训练集的样本平均值.

*`注意:threshold只在预测时使用`
如果最近临的距离大于threshold那么predict返回-1*

2·创建Fisher识别器
`
C++: Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_components=0, double threshold=DBL_MAX)
`
参数: 
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 classes c (read: subjects, persons you want to recognize). If you leave this at the default (0) or set it to a value less-equal 0 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

    3·创建LBPH人脸识别器
    `
C++: Ptr<FaceRecognizer> createLBPHFaceRecognizer(int radius=1, int neighbors=8, int grid_x=8, int grid_y=8, double threshold=DBL_MAX)
`
参数: 
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.

opencv3.0 FaceRecongnizer说明

标签:

原文地址:http://blog.csdn.net/jmh1996/article/details/51340342

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!