Ask Your Question
0

how to set a Mat object value with anther Mat

asked 2018-05-26 03:44:15 -0600

the definition of setTo function is as follows:

Mat& setTo(InputArray value, InputArray mask=noArray());

According to the definition, there is a running exception when I use the function like this:

a_mat.setTo(b_mat);//a_mat and b_mat has the same type and size

why this happened? If I want to set a Mat value to another using setTo function, is it practicable?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-05-26 03:59:32 -0600

berak gravatar image

updated 2018-05-26 04:18:24 -0600

setTo() will only work, if b_mat contains a single pixel / value (or a Scalar).

a_mat and b_mat has the same type and size

in this case, you probably wanted copyTo() , like:

b_mat.copyTo(a_mat); // note the reverse order !
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-26 03:44:15 -0600

Seen: 167 times

Last updated: May 26 '18