如何使用 c++ 在 opencv 中对浮点数进行舍入

How to round float numbers in opencv with c++

本文关键字:浮点数 舍入 何使用 c++ opencv      更新时间:2023-10-16

我想在opencv中舍入一个浮点数(或双精度)我使用了这个,但是当使用 Qt 调试时,我让它指向这一行,所以我认为我的代码是错误的:

j2 = round((theta/steptetha)+501);

opencv 将双精度舍入到最接近的整数...但要小心,如果thetasteptetha是整数,则除法结果是整数...尝试类似这样的操作:

j2 = round( ((double)theta/steptetha)+501.0);

现在((double)theta/steptetha)会给一个双倍