我想访问来自转换视频帧为灰度的openCV矩阵元素。我的代码是这样的:为什么我无法访问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矩阵的元素,但它显示的值为“double”的“-5.235125e + 30”或“ - 11242433“为”int“。这也是困惑我,我期待看到0至255之间,并
我正在使用这种方式,因为“grayPrevious.at”方法正在进行范围检查,并且对我来说耗时很长。 –
@ederman看到编辑了! – Sassa
谢谢你的回答。 –