I am trying to access openCV matrix element which comes from converting video frame into grayscale. My code is like this:
int C = 3;
cv::Mat grayPrevious;
cv::cvtColor ( previousFrame, grayPrevious, CV_RGB2GRAY );
double* grayPtr = grayPrevious.ptr <double> ();
double mean [600][800][3];
///... // set some values to mean here
for ( int i = 0; i < 600; i ++ )
{
for ( int j = 0; j < 800; j ++ )
{
for ( int m = 0; m < C; m ++ )
{
diff [i][j][m]= abs(grayPtr[ 800* (i-1)+j] - mean[i][j][m]);
}
}
}
But it crashes in the for loop. Is this something related to datatypes? How can I change it?
Besides, my second question is, I tried to see the elements of grayPrevious matrix on the screen using "grayPrevious.at", but it shows values like " -5.235125e+30" for "double", or "-11242433" for "int". This is also confusing me, I was expecting to see values between 0 and 255.