cv :: Mat matrix,HOW TO减少cv :: Mat中小数点右边的数字? [英] cv::Mat matrix, HOW TO Reduce digits to the right of the decimal point in cv::Mat?

查看:380
本文介绍了cv :: Mat matrix,HOW TO减少cv :: Mat中小数点右边的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an app that prints a 3x3 cv::Mat on the iPhone screen. I need to reduce the decimals, as the screen is not so big, see:

[1.004596557012473,-0.003116992336797859,5.936915104939593;
-0.007241746117066327,0.9973985665720294,-0.2118670500989478;
1.477734234970711e-05,-1.03363734495053e-05,1.000089074805124]

[1.004596557012473, -0.003116992336797859, 5.936915104939593; -0.007241746117066327, 0.9973985665720294, -0.2118670500989478; 1.477734234970711e-05, -1.03363734495053e-05, 1.000089074805124]

所以我想减小小数.4或.6或六个小数。任何想法?

so I would like to reduce the decimals .4 or .6 or six decimals. Any ideas?

干杯

推荐答案

c $ c> printf

If you were using 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)<<" ";
  }
}

这篇关于cv :: Mat matrix,HOW TO减少cv :: Mat中小数点右边的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆