Initialize the matrix with 255 when using openCV copyTo function?
opencv
Solution
You simply need to allocate the output matrix before copying data to it. You can create a matrix initialized with a constant as follows `Mat A(3,3,CV_32F, Scalar(255))`. Alternatively, if you have a pre-declared matrix `A`, you can re-allocate it with `A.create(3,3,CV_32F)`, and then initialize it with a constant using `A = Scalar(255)`.
So in your case you can do the following:
// Create output matrix initialized with a constant
Mat output(rows, cols, CV_8UC3, Scalar(255,255,255));
// Copy your `input` matrix into `output` through your `mask`
input.copyTo(output, mask);
Problem
When I use openCV void Mat::copyTo(OutputArray m, InputArray mask) function, newly allocated matrix is initialized with all zeros before copying the data. Is there any way to initialize with 255 instead of zeros ?