Is there a way to prevent rounding in opencv matrix divison

后端 未结 2 625
感动是毒
感动是毒 2021-01-25 00:52

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 th

2条回答
  •  抹茶落季
    2021-01-25 01:03

    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;
    

提交回复
热议问题