Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly initialize a cv::Mat pointer to a 0 matrix with zeros()

Tags:

c++

opencv

I have the following initialized at the top of a function:

cv::Mat *m;

Then, within a loop I am allocating new matrices with this name and storing them in a list. I want them to initialize as zero matrices with a specific size.

This is what I tried:

m = new cv::Mat::zeros(height, width, CV_32F);

I tried this based on the example given in the OpenCV documentation. What is the correct way to perform this operation?

like image 719
Chris Avatar asked Nov 18 '11 19:11

Chris


1 Answers

From the documentation of Mat::zeros it use used like so

cv::Mat m = cv::Mat::zeros(height, width, CV_32F);

If you want to use a Mat allocated on the heap use

cv::Mat * m = new cv::Mat( cv::Mat::zeros(height, width, CV_32F) );

// use m

delete m; // don't forget to delete m
like image 148
Tyler Hyndman Avatar answered Oct 26 '22 22:10

Tyler Hyndman