icvConvertToFastHaarFeature

来源:互联网 发布:java 加载资源文件 编辑:程序博客网 时间:2024/05/16 04:26
/* *icvConvertToFastHaarFeature *作用:将haar特征转化为快速haar特征 */void icvConvertToFastHaarFeature( CvTHaarFeature* haarFeature,       //输入数组                                  CvFastHaarFeature* fastHaarFeature, //输出数组                                  int size,                           //size表示数组的大小                                  int step )                          //step表示积分图的row step,一步可以是8位,比如灰度图;一步也可以是24位,比如RGB图{    int i = 0;//表示特征的个数    int j = 0;//表示一个特征里小矩形的个数    for( i = 0; i < size; i++ )    {        fastHaarFeature[i].tilted = haarFeature[i].tilted;        if( !fastHaarFeature[i].tilted )//当为直立特征        {            for( j = 0; j < CV_HAAR_FEATURE_MAX; j++ )            {                fastHaarFeature[i].rect[j].weight = haarFeature[i].rect[j].weight;                if( fastHaarFeature[i].rect[j].weight == 0.0F )                {                    break;                }               //下面是利用宏的定义把普通的特征转化为能快速计算的haar特征                CV_SUM_OFFSETS( fastHaarFeature[i].rect[j].p0,                                fastHaarFeature[i].rect[j].p1,                                fastHaarFeature[i].rect[j].p2,                                fastHaarFeature[i].rect[j].p3,                                haarFeature[i].rect[j].r, step )            }        }        else               //当为旋转特征时        {            for( j = 0; j < CV_HAAR_FEATURE_MAX; j++ )            {                fastHaarFeature[i].rect[j].weight = haarFeature[i].rect[j].weight;                if( fastHaarFeature[i].rect[j].weight == 0.0F )                {                    break;                }                <pre name="code" class="cpp"> CV_TILTED_OFFSETS( fastHaarFeature[i].rect[j].p0, fastHaarFeature[i].rect[j].p1,                    fastHaarFeature[i].rect[j].p2, fastHaarFeature[i].rect[j].p3, haarFeature[i].rect[j].r, step )             }        }     }}

//下面是利用宏的定义把普通的旋转特征转化为能快速计算的旋转的haar特征

其中CV_TILTED_OFFSETS为预定义好的一个宏,如下所示:

/* * get sum image offsets for <rect> corner points * step - row step (measured in image pixels!) of sum image *///CV_SUM_OFFSETS( p0, p1, p2, p3, rect, step )表示一个垂直矩形的四个顶点,其中,以左上角的点为参考点#define CV_SUM_OFFSETS( p0, p1, p2, p3, rect, step )                      \    /* (x, y) */                                                          \    (p0) = (rect).x + (step) * (rect).y;                                  \    /* (x + w, y) */                                                      \    (p1) = (rect).x + (rect).width + (step) * (rect).y;                   \    /* (x + w, y) */                                                      \    (p2) = (rect).x + (step) * ((rect).y + (rect).height);                \    /* (x + w, y + h) */                                                  \    (p3) = (rect).x + (rect).width + (step) * ((rect).y + (rect).height);/* * get tilted image offsets for <rect> corner points * step - row step (measured in image pixels!) of tilted image *///CV_TILTED_OFFSETS( p0, p1, p2, p3, rect, step ) 表示一个旋转45度矩形的四个顶点,其中以最上面那个点为参考点(x,y)#define CV_TILTED_OFFSETS( p0, p1, p2, p3, rect, step )                   \    /* (x, y) */                                                          \    (p0) = (rect).x + (step) * (rect).y;                                  \    /* (x - h, y + h) */                                                  \    (p1) = (rect).x - (rect).height + (step) * ((rect).y + (rect).height);\    /* (x + w, y + w) */                                                  \    (p2) = (rect).x + (rect).width + (step) * ((rect).y + (rect).width);  \    /* (x + w - h, y + w + h) */                                          \    (p3) = (rect).x + (rect).width - (rect).height                        \           + (step) * ((rect).y + (rect).width + (rect).height);


1 0
原创粉丝点击