Accessing each pixel of a Mat .at vs pointer arithmetic gives differnet result
Today I stumbled across this (for me) weird thing, namely when I run this code
m.convertTo(tmp_mat, CV_32FC3, 1./255);
cvtColor(tmp_mat, tmp_mat, CV_RGB2XYZ, 3);
split(tmp_mat, xyz_channels);
y_channel = xyz_channels[1].clone();
int i,j;
uint8_t* p = y_channel.data;
for( i = 0; i < y_channel.rows; ++i)
{
for ( j = 0; j < y_channel.cols; ++j)
{
std::cout << y_channel.at<float>(i,j) << std::endl;
std::cout << saturate_cast<float>(p[i*y_channel.cols + j]) << std::endl;
}
}
this is the output I get
0.984314
123
0.984314
63
0.984314
254
0.984314
251
0.984314
123
0.984314
63
0.984314
254
0.984314
251
0.984314
123
0.984314
63
...
So now I am confused - shouldn't it be same?
CV_32FC3 implies
mat.at<float>(r,c)
, notmat.at<double>(r,c)
(which would require CV_64F3C)@berak Thanks for the hint but problem is same... Please check edited question.