OpenCV机器学习库MLL


学习机器学习的时候,基本都是在用Matlab、Python写算法,做测试;

由于最近要用OpenCV写作业,兴起看了看OpenCV的机器学习模块(The Machine Learning Library——MLL)。

来看看MLL的主要构成:Statistical Model是个基类,下面的K-NN、SVM等都是其子类。

不太喜欢这个Statistical定语,Statistics在ML界横行的好多年,感觉温度已经降下来了。

来看下Statistical Model:

class CV_EXPORTS_W CvStatModel
{
public:
    CvStatModel();
    virtual ~CvStatModel();

    virtual void clear();

    CV_WRAP virtual void save( const char* filename, const char* name=0 ) const;
    CV_WRAP virtual void load( const char* filename, const char* name=0 );

    virtual void write( CvFileStorage* storage, const char* name ) const;
    virtual void read( CvFileStorage* storage, CvFileNode* node );
    virtual bool train(const Mat& train_data, const Mat& responses, Mat(), Mat(), CVParms params );
    virtual float predict(const Mat& sample, ...);

protected:
    const char* default_model_name;
};

void CvStatModel::clear() 清除内存重置模型状态;

 

void CvStatModel::save() /load() 保存/加载文件和模型;

void CvStatModel:read() /write() 读写文件和模型;

bool CvStatModel::train() 训练模型;

float CvStatModel::predict() 预测样本结果;

 

那么朴素贝叶斯、K-近邻、支持向量机、决策树等类都是继承CVStatModel;

使用这些方法的基本框架就是:

Method.train(train_data, responses, Mat(), Mat(), params);

Method.predict(sampleMat);

  • 1
  • 2
  • 下一页

相关内容