Failed to call OpenCV Mat :: zeros with size and type parameters

I am trying to create a Mat with the same size and type of another. All elements of the new Mat should be zero, so I tried the function Mat::zeros(size, type) , defined as:

 static MatExpr zeros(Size size, int type); 

This is my code. Suppose I already have Mat g (created using imread ):

 Mat h = Mat::zeros(g.size, g.type()); 

This will give me a compiler error complaining that:

There is no corresponding function to call "zeros"

What am I doing wrong?

+6
source share
1 answer

You stumbled upon one of the quirks of cv::Mat . The size field does not return a cv::Size structure, but rather a Mat::MSize . This MSize can be converted to cv::Size by calling its operator() .

You need to call like this:

 Mat h = Mat::zeros(g.size(), g.type()); 
+11
source

Source: https://habr.com/ru/post/952603/


All Articles