I'm facing a strange problem.
My Mat is declared as:
cv::Mat matr(src.rows, src.cols, CV_32FC1);
If i print it using cout<<matr
I get all the data in range from 0 to 255 and everything is fine.
If I try to access using this cycle:
float* matrF= (float*)matr.data;
for (int r=0; r<matrF.rows; r++)
{
for (int c=0; c<matrF.cols; c++)
{
std::cout<<matrF[r*matr.cols+c]<<std::endl;
}
}
I get many values like: 4.684e-42, 2.223e-22
ecc.
If I use
for (int r=0; r<matrF.rows; r++)
{
for (int c=0; c<matrF.cols; c++)
{
std::cout<<matr.data[r*matr.cols+c]<<std::endl;
}
}
It print some random char and no values.
Ho can I access the element printed using cout<<matr
?
I don't want to use function from openCV to access them, I'm trying to loop over the matr.data...
I cant't use mat.at<float>
or .step1()
.
Thanks.
---------- SOLUTION
if instead of
for (int r=0; r<matrF.rows; r++)
{
for (int c=0; c<matrF.cols; c++)
{
std::cout<<matrF.data[r*matr.cols+c]<<std::endl;
}
}
I use
for (int r=0; r<matrF.rows; r++)
{
for (int c=0; c<matrF.cols; c++)
{
float val = matF.data[r*matr.cols+c];
std::cout<<val<<std::endl;
}
}
the problem disappears.