First time here? Check out the FAQ!

Ask Your Question
0

Offset calculation for a Mat object (traincascade)

asked Mar 18 '15

fatih gravatar image

updated Mar 18 '15

Hi,

offset is calculated as int offset = winSize.width + 1;in line 123 of https://github.com/Itseez/opencv/blob... file.

This offset is renamed as step and then step is used to calculate some p values in https://github.com/Itseez/opencv/blob... file by multiplying with combinations of some parameters of the rect rectangle in CV_SUM_OFFSETS definition:

#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);

These p values are later used in line 79 of https://github.com/Itseez/opencv/blob... file, to access locations in integral sum images (tilted or untilted one), like:

inline float CvHaarEvaluator::Feature::calc( const cv::Mat &_sum, const cv::Mat &_tilted, size_t y) const
{
    const int* img = tilted ? _tilted.ptr<int>((int)y) : _sum.ptr<int>((int)y);
    float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) +
        rect[1].weight * (img[fastRect[1].p0] - img[fastRect[1].p1] - img[fastRect[1].p2] + img[fastRect[1].p3] );
    if( rect[2].weight != 0.0f )
        ret += rect[2].weight * (img[fastRect[2].p0] - img[fastRect[2].p1] - img[fastRect[2].p2] + img[fastRect[2].p3] );
    return ret;
}

what is the purpose of this +1 in int offset = winSize.width + 1;, why is it not int offset = winSize.width;? By adding this one I suspect that we are calculating incorrect p values. An explanation on these p values is available at http://docs.opencv.org/modules/imgpro...

Preview: (hide)

1 answer

Sort by » oldest newest most voted
4

answered Mar 18 '15

Daniil Osokin gravatar image

This is due to cv::integral(). It creates output of (rows + 1, cols + 1) size (adds extra 0 row and column), so the stride between rows of integral sum images grows to width + 1.

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Mar 18 '15

Seen: 901 times

Last updated: Mar 18 '15