opencv – cv :: Mat矩阵,如何减少cv :: Mat中小数点右边的数字?

我有一个应用程序在iPhone屏幕上打印3×3 cv :: Mat.我需要减少小数,因为屏幕不是那么大,请参阅:

[1.004596557012473,-0.003116992336797859,5.936915104939593;
  -0.007241746117066327,0.99973985665720294,-0.2118670500989478;
  1.477734234970711e-05,-1.03363734495053e-05,1.00000089074805124]

所以我想减少小数.4或.6或六位小数.有任何想法吗?

干杯

最佳答案
如果你使用printf

cv::Mat data(3, 3, CV_64FC1);
for (int y = 0; y < data.rows; ++y) {
  for (int x = 0;x < data.cols; ++x) {
    printf("%.6f ", data.at<double>(y, x));
  }
}

如果你使用std :: cout

cv::Mat data(3, 3, CV_64FC1);
std::cout.setf(std::ios::fixed, std:: ios::floatfield);
std::cout.precision(6);
for (int y = 0; y < data.rows; ++y) {
  for (int x = 0;x < data.cols; ++x) {
    std::cout<<data.at<double>(y, x)<<" ";
  }
}

转载注明原文:opencv – cv :: Mat矩阵,如何减少cv :: Mat中小数点右边的数字? - 代码日志