I'm trying to create a Mat
with the same size and type of another one. All elements of the new Mat
should be zero, so I tried the Mat::zeros(size, type)
function, defined as:
static MatExpr zeros(Size size, int type);
This is my code. Assume I already have a Mat g
(created via imread
):
Mat h = Mat::zeros(g.size, g.type());
This will give me a compiler error, complaining that:
No matching function for call to 'zeros'
What am I doing wrong?
You've stumbled upon one of the quirks of cv::Mat
. The size
field does not return a cv::Size
, but rather a Mat::MSize
structure. This MSize
can be converted to a cv::Size
by calling its operator()
.
You need to call like this:
Mat h = Mat::zeros(g.size(), g.type());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With