DSP

OPENCV haarcascade文件解析

2019-07-13 19:11发布

 因为要用DSP加载这个haarcascade的XML文件,所以今天仔细看了下OPENCV的文档,讲的很详细,在这里作记录,希望对别人也有启发。
haar feather-based cascade classifier for object detection 是由paul viola提出,由rainer lienhart改进。首先,分类器是由数千个一致尺寸的特定物体我们称为正例和反例训练出来。在分类器训练以后,可以用来对一幅图像的区域作出检测。分类器如果检测到该物体跟训练物体类似就输出1,否则输出0.在一幅图像中搜索目标,可以在图像上移动整个搜索窗口。分类器设计成很容易改变尺寸,这比改变图像的尺寸效率更高。所以要在一幅图像中找到未知尺寸的物体,需要对不同的比例作多次扫描。 Boosted Haar classifier structures.
#define CV_HAAR_FEATURE_MAX 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;
haar特征包括一个tilted标志,tilted = 0  是直立型特征  
tilted =1  是45度特征
特征是2-3 个带权重的矩形,如果rect[2].weight != 0 则特征是3个矩形,否则是 2 个矩形
/* 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 response */
typedef struct CvHaarClassifier
{
int count; /* number of nodes in the decision tree */
/* these are "parallel" arrays. Every index exttt{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 chosen.
alpha[i] - output value correponding to the leaf. */
CvHaarFeature* haar_feature;
float* threshold;
int* left;
int* right;
float* alpha;
}
CvHaarClassifier; haar分类器的结构如上面的代码所示,对比下面的haarcascade分类器更容易理解      
     
        <_>
         
          <_>
           
           
             
                <_>2 7 16 4 -1.
                <_>2 9 16 2 2.
    
              0

            4.3272329494357109e-003
            0.0383819006383419
            1