Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the cv::Mat contents?

Tags:

I have a cv::Mat but I have already insert it with some values, how do I clear the contents in it?

Thank you

like image 719
anarchy99 Avatar asked May 29 '13 14:05

anarchy99


People also ask

How to clear Mat in OpenCV?

If you want to release the memory of the Mat variable use release() . Mat m; // initialize m or do some processing m. release(); For a vector of cv::Mat objects you can release the memory of the whole vector with myvector.

What is mat in cv2?

The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.


2 Answers

If you want to release the memory of the Mat variable use release().

Mat m; // initialize m or do some processing m.release(); 

For a vector of cv::Mat objects you can release the memory of the whole vector with myvector.clear().

std::vector<cv::Mat> myvector; // initialize myvector ..   myvector.clear(); // to release the memory of the vector 
like image 136
Alexey Avatar answered Sep 20 '22 15:09

Alexey


From the docs:

// sets all or some matrix elements to s Mat& operator = (const Scalar& s); 

then we could do

m = Scalar(0,0,0); 

to fill with black pixels. Scalar has 4 components, the last - alpha - is optional.

like image 27
CapelliC Avatar answered Sep 17 '22 15:09

CapelliC