I have a cv::Mat
but I have already insert it with some values, how do I clear the contents in it?
Thank you
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.
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.
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
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.
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