I have the following code:
cv::Mat data ( HEIGHT,WIDTH, CV_32SC1 );
cv::Mat means = cv::Mat::zeros (HEIGHT, WIDTH, CV_64FC1 );
int *dPtr = new int [HEIGHT*WIDTH];
dPtr = data.ptr<int>();
double *mPtr = new double [HEIGHT*WIDTH];
mPtr = means.ptr < double>();
for ( int i = 0; i < N; i ++)
{
for ( int j = 0; j < M; j ++ )
{
mPtr[ WIDTH * (i-1) + j ] += dPtr[ WIDTH * (i-1) + j ];
}
}
But the program crashes inside the for loop, and I doubt I am somehow exceeding the matrix size. But I cannot figure it out. Could someone help me? Thank you in advance.
Since your indices i,j start with 0 you should omit the -1 in the array expressions (i-1).