# Offset calculation for a Mat object (traincascade)

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...