返回信息流我想计算Haar特征,自己手动计算感觉挺麻烦(主要在取各个不同位置、不同scale的特征),而且可能速度不够。在网上搜了些材料,有个NTU的是用python写的,不是很有明白。有个俄罗斯的人写了,但是他说他光写配置特征位置和尺度的文件就写了好几天。
OpenCV的这个把所有东西都封装起来了,由于我的online-boosting和它的框架不一样,不能直接使用。我在源码中看了半天,发现里面又有internal haar feature又有fast haar feature,还有什么Thaar feature。源码中注释比较少,看不太明白。请问哪一段是计算Haar特征的呢?主要是涉及到尺度的选择和特征位置的对应。
谢谢!
这是一条镜像帖。来源:北邮人论坛 / ml-dm / #3946同步于 2008/12/25
该镜像源已超过 30 天没有更新,可能在源站已被删除。
ML_DM机器人发帖
[求助]OpenCV源码中真正计算Haar特征的那段在哪?
zixu1986
2008/12/25镜像同步10 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
啊。。。lz弄清楚了。。告诉我们吧。。。。
【 在 zixu1986 (Euro) 的大作中提到: 】
: 我想计算Haar特征,自己手动计算感觉挺麻烦(主要在取各个不同位置、不同scale的特征),而且可能速度不够。在网上搜了些材料,有个NTU的是用python写的,不是很有明白。有个俄罗斯的人写了,但是他说他光写配置特征位置和尺度的文件就写了好几天。
: OpenCV的这个把所有东西都封装起来了,由于我的online-boosting和它的框架不一样,不能直接使用。我在源码中看了半天,发现里面又有internal haar feature又有fast haar feature,还有什么Thaar feature。源码中注释比较少,看不太明白。请问哪一段是计算Haar特征的呢?
: 谢谢!
: ...................
不知道,只找到这个
CvHaarFeature, CvHaarClassifier, CvHaarStageClassifier, CvHaarClassifierCascade
CvHaarFeature, CvHaarClassifier, CvHaarStageClassifier, CvHaarClassifierCascade
Boosted Haar 分类器结构
#define CV_HAAR_FEATURE_MAX 3
/* 一个 harr 特征由 2-3 个具有相应权重的矩形组成 */
/* a haar feature consists of 2-3 rectangles with appropriate weights */
typedef struct CvHaarFeature
{
int tilted; /* 0 means up-right feature, 1 means 45--rotated feature */
/* 2-3 rectangles with weights of opposite signs and
with absolute values inversely proportional to the areas of the rectangles.
if rect[2].weight !=0, then
the feature consists of 3 rectangles, otherwise it consists of 2 */
struct
{
CvRect r;
float weight;
} rect[CV_HAAR_FEATURE_MAX];
}
CvHaarFeature;
/* a single tree classifier (stump in the simplest case) that returns the response for the feature
at the particular image location (i.e. pixel sum over subrectangles of the window) and gives out
a value depending on the responce */
typedef struct CvHaarClassifier
{
int count; /* number of nodes in the decision tree */
/* these are "parallel" arrays. Every index i
corresponds to a node of the decision tree (root has 0-th index).
left[i] - index of the left child (or negated index if the left child is a leaf)
right[i] - index of the right child (or negated index if the right child is a leaf)
threshold[i] - branch threshold. if feature responce is <= threshold, left branch
is chosen, otherwise right branch is chosed.
alpha[i] - output value correponding to the leaf. */
CvHaarFeature* haar_feature;
float* threshold;
int* left;
int* right;
float* alpha;
}
CvHaarClassifier;
/* a boosted battery of classifiers(=stage classifier):
the stage classifier returns 1
if the sum of the classifiers' responces
is greater than threshold and 0 otherwise */
typedef struct CvHaarStageClassifier
{
int count; /* number of classifiers in the battery */
float threshold; /* threshold for the boosted classifier */
CvHaarClassifier* classifier; /* array of classifiers */
/* these fields are used for organizing trees of stage classifiers,
rather than just stright cascades */
int next;
int child;
int parent;
}
CvHaarStageClassifier;
typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade;
/* cascade or tree of stage classifiers */
typedef struct CvHaarClassifierCascade
{
int flags; /* signature */
int count; /* number of stages */
CvSize orig_window_size; /* original object size (the cascade is trained for) */
/* these two parameters are set by cvSetImagesForHaarClassifierCascade */
CvSize real_window_size; /* current object size */
double scale; /* current scale */
CvHaarStageClassifier* stage_classifier; /* array of stage classifiers */
CvHidHaarClassifierCascade* hid_cascade; /* hidden optimized representation of the cascade,
created by cvSetImagesForHaarClassifierCascade */
}
CvHaarClassifierCascade;
所有的结构都代表一个级联boosted Haar分类器。级联有下面的等级结构:
Cascade:
Stage1:
Classifier11:
Feature11
Classifier12:
Feature12
...
Stage2:
Classifier21:
Feature21
...
...
整个等级可以手工构建,也可以利用函数cvLoadHaarClassifierCascade从已有的磁盘文件或嵌入式基中导入。
求一个具体的haar特征很好做
麻烦的是每个haar特征的位置 如果涉及到不同尺度的话
【 在 bebekifis 的大作中提到: 】
: haar特征,用积分图像去做,很简单。
这个是OpenCV文档中的吧
在OpenCV论坛中问了下 一个人给出了源码中的几个函数
//针对大小为winsize的图,计算所有HaarFeature的rect,存入features返回,即获取所有特征坐标
CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
int mode,
int symmetric )
//训练样本图集
//创建结构CvHaarTrainigData,分配空间,并未填入sample数据
CvHaarTrainigData* icvCreateHaarTrainingData( CvSize winsize, int maxnumsamples )
//计算训练样本集的特征值,调用icvGetTrainingDataCallback
//已知训练样本的积分图,计算特征值valcache、索引idxcache
void icvPrecalculate( CvHaarTrainingData* data, CvIntHaarFeatures* haarFeatures,
int numprecalculated )//numprecalculated:要计算的特征数
//userdata:含训练数据、haar特征
//计算从first开始的num个特征,结果存入mat
//若sampleIdx为null,则计算全部样本,否则计算由sampleIdx指定的样本
void icvGetTrainingDataCallback( CvMat* mat, CvMat* sampleIdx, CvMat*,
int first, int num, void* userdata )
//计算一个样本(积分图为sum和tilted)的一个HaarFeature,并返回该值
CV_INLINE float cvEvalFastHaarFeature( CvFastHaarFeature* feature,
sum_type* sum, sum_type* tilted )
//特征的rect由坐标表示转换为由像素索引表示
//每个haarFeature最多由3个rect组成,但都保留3个的存储空间
void icvConvertToFastHaarFeature( CvTHaarFeature* haarFeature,
CvFastHaarFeature* fastHaarFeature,
int size, int step )
【 在 mousie 的大作中提到: 】
: 不知道,只找到这个
: CvHaarFeature, CvHaarClassifier, CvHaarStageClassifier, CvHaarClassifierCascade
:
: ...................
完全看不定~
【 在 zixu1986 (Euro) 的大作中提到: 】
: 这个是OpenCV文档中的吧
: 在OpenCV论坛中问了下 一个人给出了源码中的几个函数
: //针对大小为winsize的图,计算所有HaarFeature的rect,存入features返回,即获取所有特征坐标
: ...................
自己写一个吧,用 integral image 方法。应该比较简单
【 在 zixu1986 的大作中提到: 】
: 我想计算Haar特征,自己手动计算感觉挺麻烦(主要在取各个不同位置、不同scale的特征),而且可能速度不够。在网上搜了些材料,有个NTU的是用python写的,不是很有明白。有个俄罗斯的人写了,但是他说他光写配置特征位置和尺度的文件就写了好几天。
: OpenCV的这个把所有东西都封装起来了,由于我的online-boosting和它的框架不一样,不能直接使用。我在源码中看了半天,发现里面又有internal haar feature又有fast haar feature,还有什么Thaar feature。源码中注释比较少,看不太明白。请问哪一段是计算Haar特征的呢?主要是涉及到尺度的选择和特征位置的对应。
: 谢谢!