一、参考OpenCV的CascadeClassifier类LBPEvaluator类

如下,筛选出存放分类器相关信息的成员变量:

class CV_EXPORTS_W CascadeClassifier
{
public:
CV_WRAP CascadeClassifier();
CV_WRAP CascadeClassifier( const string& filename );
virtual ~CascadeClassifier(); CV_WRAP virtual bool empty() const;
CV_WRAP bool load( const string& filename );
virtual bool read( const FileNode& node );
CV_WRAP virtual void detectMultiScale( const Mat& image,
CV_OUT vector<Rect>& objects,
double scaleFactor=1.1,
int minNeighbors=, int flags=,
Size minSize=Size(),
Size maxSize=Size() ); CV_WRAP virtual void detectMultiScale( const Mat& image,
CV_OUT vector<Rect>& objects,
vector<int>& rejectLevels,
vector<double>& levelWeights,
double scaleFactor=1.1,
int minNeighbors=, int flags=,
Size minSize=Size(),
Size maxSize=Size(),
bool outputRejectLevels=false ); bool isOldFormatCascade() const;
virtual Size getOriginalWindowSize() const;
int getFeatureType() const;
bool setImage( const Mat& ); protected:
//virtual bool detectSingleScale( const Mat& image, int stripCount, Size processingRectSize,
// int stripSize, int yStep, double factor, vector<Rect>& candidates ); virtual bool detectSingleScale( const Mat& image, int stripCount, Size processingRectSize,
int stripSize, int yStep, double factor, vector<Rect>& candidates,
vector<int>& rejectLevels, vector<double>& levelWeights, bool outputRejectLevels=false); protected:
enum { BOOST = };
enum { DO_CANNY_PRUNING = , SCALE_IMAGE = ,
FIND_BIGGEST_OBJECT = , DO_ROUGH_SEARCH = }; friend class CascadeClassifierInvoker; template<class FEval>
friend int predictOrdered( CascadeClassifier& cascade, Ptr<FeatureEvaluator> &featureEvaluator, double& weight); template<class FEval>
friend int predictCategorical( CascadeClassifier& cascade, Ptr<FeatureEvaluator> &featureEvaluator, double& weight); template<class FEval>
friend int predictOrderedStump( CascadeClassifier& cascade, Ptr<FeatureEvaluator> &featureEvaluator, double& weight); template<class FEval>
friend int predictCategoricalStump( CascadeClassifier& cascade, Ptr<FeatureEvaluator> &featureEvaluator, double& weight); bool setImage( Ptr<FeatureEvaluator>& feval, const Mat& image);
virtual int runAt( Ptr<FeatureEvaluator>& feval, Point pt, double& weight ); class Data
{
public:
struct CV_EXPORTS DTreeNode
{
int featureIdx;
float threshold; // for ordered features only
int left;
int right;
}; struct CV_EXPORTS DTree
{
int nodeCount;
}; struct CV_EXPORTS Stage
{
int first;
int ntrees;
float threshold;
}; bool read(const FileNode &node); bool isStumpBased; int stageType;
int featureType;
int ncategories;
Size origWinSize; vector<Stage> stages;
vector<DTree> classifiers;
vector<DTreeNode> nodes;
vector<float> leaves;
vector<int> subsets;
}; Data data;
Ptr<FeatureEvaluator> featureEvaluator;
Ptr<CvHaarClassifierCascade> oldCascade; public:
class CV_EXPORTS MaskGenerator
{
public:
virtual ~MaskGenerator() {}
virtual cv::Mat generateMask(const cv::Mat& src)=;
virtual void initializeMask(const cv::Mat& /*src*/) {};
};
void setMaskGenerator(Ptr<MaskGenerator> maskGenerator);
Ptr<MaskGenerator> getMaskGenerator(); void setFaceDetectionMaskGenerator(); protected:
Ptr<MaskGenerator> maskGenerator;
}; class LBPEvaluator : public FeatureEvaluator
{
public:
struct Feature
{
Feature();
Feature( int x, int y, int _block_w, int _block_h ) :
rect(x, y, _block_w, _block_h) {} int calc( int offset ) const;
void updatePtrs( const Mat& sum );
bool read(const FileNode& node ); Rect rect; // weight and height for block
const int* p[]; // fast
}; LBPEvaluator();
virtual ~LBPEvaluator(); virtual bool read( const FileNode& node );
virtual Ptr<FeatureEvaluator> clone() const;
virtual int getFeatureType() const { return FeatureEvaluator::LBP; } virtual bool setImage(const Mat& image, Size _origWinSize);
virtual bool setWindow(Point pt); int operator()(int featureIdx) const
{ return featuresPtr[featureIdx].calc(offset); }
virtual int calcCat(int featureIdx) const
{ return (*this)(featureIdx); }
protected:
Size origWinSize;
Ptr<vector<Feature> > features;
Feature* featuresPtr; // optimization
Mat sum0, sum;
Rect normrect; int offset;
};

二、开始设计适合自己分类器的数据结构

如下图,因为我们打算使用数组方式存储信息,为避免溢出,首先了解自己分类器的强分类器级数,nodes,leaves等信息,由于我们的分类器是通过opencv训练的,所以可以直接Debug查看分类器信息,或者通过xml文件查看。

设计结构体如下:

#ifndef    _CP_ADABOOST_
#define _CP_ADABOOST_
#ifdef __cplusplus
extern "C"{
#endif
typedef struct tagCpSize
{
int iWidth;
int iHeight;
}CP_SIZE_S; typedef struct tagCPDTreeNode
{
int featureIdx;
float threshold; // for ordered features only
int left;
int right;
}CP_DTREE_NODE_S; typedef struct tagCpDTree
{
int nodeCount;
}CP_DTREE_S; typedef struct tagCpStage
{
int first;
int ntrees;
float threshold;
}CP_STAGE_S; typedef struct tagCPRect
{
int x;
int y;
int width;
int height;
}CP_RECT_S; typedef struct tagLBPFeature
{
CP_RECT_S rect;/*特征位置*/
int* p[];/* 特征在积分图中的地址 */
}CP_LBP_FEATURE_S; typedef struct tagCpClassifier
{
bool isStumpBased; int stageType;
int featureType;
int ncategories;
CP_SIZE_S origWinSize; CP_STAGE_S stages[]; /*强分类器级数*/
int stagerNum;
CP_DTREE_S classifiers[];
int classfierNum;
CP_DTREE_NODE_S nodes[];
int nodeNum;
CP_LBP_FEATURE_S feature[];
int featureNum;
float leaves[];
int leaveNum;
int subsets[];
int subsetNum;
}CP_CLASSIFIER_S; #ifdef __cplusplus
}
#endif
#endif /* _CP_ADABOOST_ */

【Adaboost算法】C++转C, 分类器结构设计的更多相关文章

  1. Adaboost 算法

    一 Boosting 算法的起源 boost 算法系列的起源来自于PAC Learnability(PAC 可学习性).这套理论主要研究的是什么时候一个问题是可被学习的,当然也会探讨针对可学习的问题的 ...

  2. Adaboost 算法的原理与推导

    0 引言 一直想写Adaboost来着,但迟迟未能动笔.其算法思想虽然简单“听取多人意见,最后综合决策”,但一般书上对其算法的流程描述实在是过于晦涩.昨日11月1日下午,邹博在我组织的机器学习班第8次 ...

  3. Adaboost算法初识

    1.算法思想很简单: AdaBoost 是一种迭代算法,其核心思想是针对同一个训练集训练不同的分类器,即弱分类器,然后把这些弱分类器集合起来,构造一个更强的最终分类器.(三个臭皮匠,顶个诸葛亮) 它的 ...

  4. adaboost算法

    三 Adaboost 算法 AdaBoost 是一种迭代算法,其核心思想是针对同一个训练集训练不同的分类器,即弱分类器,然后把这些弱分类器集合起来,构造一个更强的最终分类器.(很多博客里说的三个臭皮匠 ...

  5. 前向分步算法 && AdaBoost算法 && 提升树(GBDT)算法 && XGBoost算法

    1. 提升方法 提升(boosting)方法是一种常用的统计学方法,在分类问题中,它通过逐轮不断改变训练样本的权重,学习多个分类器,并将这些分类器进行线性组合,提高分类的性能 0x1: 提升方法的基本 ...

  6. 集成学习值Adaboost算法原理和代码小结(转载)

    在集成学习原理小结中,我们讲到了集成学习按照个体学习器之间是否存在依赖关系可以分为两类: 第一个是个体学习器之间存在强依赖关系: 另一类是个体学习器之间不存在强依赖关系. 前者的代表算法就是提升(bo ...

  7. Adaboost 算法实例解析

    Adaboost 算法实例解析 1 Adaboost的原理 1.1 Adaboost基本介绍 AdaBoost,是英文"Adaptive Boosting"(自适应增强)的缩写,由 ...

  8. 浅谈 Adaboost 算法

    http://blog.csdn.net/haidao2009/article/details/7514787 菜鸟最近开始学习machine learning.发现adaboost 挺有趣,就把自己 ...

  9. 机器学习--boosting家族之Adaboost算法

    最近在系统研究集成学习,到Adaboost算法这块,一直不能理解,直到看到一篇博文,才有种豁然开朗的感觉,真的讲得特别好,原文地址是(http://blog.csdn.net/guyuealian/a ...

  10. Adaboost 算法的原理与推导——转载及修改完善

    <Adaboost算法的原理与推导>一文为他人所写,原文链接: http://blog.csdn.net/v_july_v/article/details/40718799 另外此文大部分 ...

随机推荐

  1. 【Spring】利用AOP来做系统性能监控

    需求: 假设已经有了一些类,现在想统计每个方法调用花了多长时间,该怎么做? 思路: 我第一个想法就是去每个方法执行前后记录一下当前的时间戳,然后相减统计到日志. OK,没问题,那么这样做合理吗? 首先 ...

  2. CentOS6.5菜鸟之旅:安装VirtualBox4.3

    一.下载VirtualBox的RHEL软件库配置文件 cd /etc/yum.repos.d wget http://download.virtualbox.org/virtualbox/rpm/rh ...

  3. NetworkComms.Net github下载地址

    https://github.com/MarcFletcher/NetworkComms.Net

  4. HTML5标准简介

    最近前端的群都蛮热闹的,但我发现多数讨论的是javascript和css相关的问题,仿佛大家在努力创建各种交互.样式的时候,忘却了这一切的基础 – HTML. 其实我很喜欢HTML,觉得这个语言远比X ...

  5. 记录一次Mac虚拟机安装的过程(有图有真相)

    这是我今天在公司用Vmware workstation虚拟机安装小狮子的全过程,记录一下没什么特别的用途,希望以后不要忘记,整个过程我总共花了半个多小时,挺快的.确实苹果的系统配上苹果的电脑就是牛叉, ...

  6. macbook 我们需要买吗

    能否写出好代码与是否使用“好”的电脑是没有直接关系的.

  7. 才知道百度也提供了智能DNS服务 - 加速乐

    http://jiasule.baidu.com/ 智能DNS 依托百度多年积累的高精度DNS识别库,平均只需5秒全球DNS服务器全部生效,百度蜘蛛1秒生效.抗攻击.无限解析记录,免费支持电信.联通. ...

  8. YII页面跳转

    $criteria = new CDbCriteria; $criteria->select = array('ziduan"); $res = Model::model()-> ...

  9. j2ee分布式缓存同步实现方案dlcache v1.0.0

    现成的分布式K/V缓存已经有很多的实现,最主要的比如redis,memcached,couchbase.那为什么我们还要自己去实现呢,在我们解决了分布式系统下大量rpc调用导致的高延时后,我们发现很多 ...

  10. Android笔记——Android中数据的存储方式(三)

    Android系统集成了一个轻量级的数据库:SQLite,所以Android对数据库的支持很好,每个应用都可以方便的使用它.SQLite作为一个嵌入式的数据库引擎,专门适用于资源有限的设备上适量数据存 ...