有没有一种方法可以防止在opencv矩阵除法中舍入 [英] Is there a way to prevent rounding in opencv matrix divison

查看:133
本文介绍了有没有一种方法可以防止在opencv矩阵除法中舍入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个整数矩阵,我想对其进行整数除法.但是opencv总是将结果取整. 我知道我可以手动划分每个元素,但是我想知道是否有更好的方法?

I have an integer matrix and I want to perform an integer division on it. But opencv always rounds the result. I know I can divide each element manually but I want to know is there a better way for this or not?

Mat c = (Mat_ <int> (1,3) << 80,71,64 );
cout << c/8 << endl;

// result
//[10, 9, 8]

// desired result
//[10, 8, 8]

推荐答案

类似于@GPPK的可选方法,您可以通过以下方式对其进行破解:

Similar to @GPPK's optional method, you can hack it by:

Mat tmp, dst;
c.convertTo(tmp, CV_64F);
tmp = tmp / 8 - 0.5;            // simulate to prevent rounding by -0.5
tmp.convertTo(dst, CV_32S);

cout << dst;

这篇关于有没有一种方法可以防止在opencv矩阵除法中舍入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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