我正在尝试访问来自将视频帧转换为灰度的 openCV 矩阵元素。我的代码是这样的:
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]);
}
}
}
但它在 for 循环中崩溃。这与数据类型有关吗?我怎样才能改变它?
此外,我的第二个问题是,我尝试使用“grayPrevious.at”在屏幕上查看 grayPrevious 矩阵的元素,但它显示的值如“-5.235125e+30”代表“double”,或“-11242433”代表“诠释”。这也让我感到困惑,我期待看到 0 到 255 之间的值。