Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to call OpenCV's Mat::zeros with size and type parameters

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?

like image 422
cfischer Avatar asked Aug 27 '13 15:08

cfischer


1 Answers

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());
like image 186
Aurelius Avatar answered Sep 23 '22 15:09

Aurelius