Ask Your Question
0

Mat::convertTo

asked 2016-09-17 23:40:32 -0600

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-09-18 00:59:36 -0600

berak gravatar image

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]
edit flag offensive delete link more

Comments

Oh, I see, thank you very much !

Heinrich gravatar imageHeinrich ( 2016-09-19 04:51:44 -0600 )edit

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?

Heinrich gravatar imageHeinrich ( 2016-09-19 04:57:11 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-17 23:39:42 -0600

Seen: 2,306 times

Last updated: Sep 18 '16