Mat::convertTo
I have read the documentation for convertto but i can't seem to understand the scale argument. What is its purpose? After testing it, the size of the mat object is still the same. So what does it do?
I have read the documentation for convertto but i can't seem to understand the scale argument. What is its purpose? After testing it, the size of the mat object is still the same. So what does it do?
the scale factor is applied to the (pixel) values, not to the size of the Mat.
an example:
Mat m1(3,3,CV_32F, 2.0f);
cerr << m1 << endl;
[2, 2, 2;
2, 2, 2;
2, 2, 2]
Mat m2;
m1.convertTo(m2, CV_8U, 0.5);
cerr << m2 << endl;
[1, 1, 1;
1, 1, 1;
1, 1, 1]
How does it handle overflows then like what if it was Mat m1 with type CV_32F and values [2, 2, 2; 2, 2, 2; 2, 2, 2] then we do m1.convertTo(m1, CV_8UC1, 255); I believe this would lead to [510, 510, 510; 510, 510, 510; 510, 510, 510] If im not mistaken. But unsigned ints only have a max value of 255? so is it set to 255 if it exceeds the maximum possible value?
Asked: 2016-09-17 23:39:42 -0600
Seen: 2,704 times
Last updated: Sep 18 '16