Is there a way to prevent rounding in opencv matrix divison

后端 未结 2 622
感动是毒
感动是毒 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:08

    The problem is with using ints, you cant have decimal points with ints so I'm not sure how you are expecting not to get rounding.

    You really have two options here, I do not think you can this without using one of these options:

    1. You have a mathematically correct int matrix division [10, 9, 8]
    2. You spin up your own divide function in order to give you the result you want.

    Option 2:

    Pseudocode:

    Create a double matrix
    perform the division to get the output [10.0, 8.875, 8.0]
    strip away any numbers after a decimal point [10.0, 8.0, 8.0]
    (optional) write these values back to a int matrix
    (result) [10, 8, 8]
    

提交回复
热议问题