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
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;
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:
int
matrix division [10, 9, 8]
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]