opencv 2.4.2之face Recognizer(一)

来源:互联网 发布:约瑟夫环java数组 编辑:程序博客网 时间:2024/04/28 17:33

2012年7月4号,opencv2.4.2正式发布了。一直都是用的是是2.2及2.0的版本,这次还是关注了新的版本。

各版本的下载地址:

windows:http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.2/OpenCV-2.4.2.exe/download

linux/mac:http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.2/OpenCV-2.4.2.tar.bz2/download

android:http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.2/OpenCV-2.4.2-android-sdk.zip/download

ios:http://sourceforge.net/projects/opencvlibrary/files/opencv-ios/2.4.2/opencv2.framework.zip/download

看得出来,opencv支持的越来越多了,貌似以前在windows和linux版本中包含for android sdk,现在都独立发布了,还单独发布了ios版本的。自从2.2之后,很多函数都做了优化,用C++类重新编写。

言归正传,我比较感兴趣的是,FaceRecognizer - Face Recognition with OpenCV这个模块。其中脸部跟踪类继承自Algorithm类,

class FaceRecognizer : public Algorithm
{
public:
//! virtual destructor
virtual ~FaceRecognizer() {}
// Trains a FaceRecognizer.
virtual void train(InputArray src, InputArray labels) = 0;
// 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;
};

其中Algorithm类作为基类,其为继承类提供了下列特性:

1. 虚构造函数;

2.根据名字来设置/获得算法参数,有Algorithm::set() and Algorithm::get()等。

3.从XML/YAML文件中读写参数。

关于FaceRecognizer类,从类的定义中可以看出,其提供了FaceRecognizer::train()算法,能对你的脸部数据库进行训练。一般需要你的图像格式为pgm格式。

预测所给样本图像用其提供的Prediction算法;还能从XML/YAML中Loading/Saving模型。

人脸识别所用的算法有,特征脸(EigenFace),FiserFace和LBPH三种。

其中,EigenFace的,C++: Ptr<FaceRecognizer> createEigenFaceRecognizer(int num_components=0, double threshold=DBL_MAX)。

FisherFace算法,C++: Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_components=0, double threshold=
DBL_MAX)。

LBPH(Local binary pattern histograms),C++: Ptr<FaceRecognizer> createLBPHFaceRecognizer(int radius=1, int neighbors=8, int grid_x=8, int
grid_y=8, double threshold=DBL_MAX)。