Ask Your Question
1

Fill a matrix

asked 2013-02-26 09:06:09 -0600

Tom Sgouros gravatar image

What is the easiest way to fill a cv::Mat object with scalars of a single value?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-02-26 09:59:17 -0600

You can use matrix multiplication for single channel, or setTo function for multiple channels:

cv::Mat mat = cv::Mat::ones(rows,cols,CV_8UC1);
mat *= 12; // to set all values to 12
std::cout << mat << std::endl;
// To set a multi dimensional matrix
cv::mat mat2 = cv::Mat(rows,cols,CV_8UC2);
mat2.setTo(cv::Scalar(12,12)); // to set all values to 12
std::cout << mat2 << std::endl;
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-26 09:06:09 -0600

Seen: 3,924 times

Last updated: Feb 26 '13