Mat ptr<double> avoid truncation

When I take values of a Mat use ptr(r)[c],decimals are reserved for two significant digits.How to avoid truncation of numbers?

can you show example code to reproduce it, please ?

1 Like

Mat cameraMatrix;
FileStorage fs("./calibrate.xml",FileStorage::READ);
fs[“distCoeffs”]>>distCoeffs;
fs[“cameraMatrix”]>>cameraMatrix;
fs.release();
cout<<cameraMatrix<<endl;
// [1469.755863637623, 0, 800.3226944488998;

0, 1463.060248847902, 604.1622846498016;

0, 0, 1]

cout<<cameraMatrix.ptr(0)[0]<<endl;
// I got 1469.76 ,but not 1469.755863637623. How to get 1469.755863637623?
Thanks!

the << operator for cv::Mat is changing the precision (for printing) internally.
you can do the same:

double d = 12.3456789;
cout << d << endl; // default is 6 digits
cout << std::setprecision(10) << d << endl;

12.3457
12.3456789
1 Like

Thank you for your very clear and timely answer to this question~

1 Like