Will cv::Mat reuse memory if it was declared inside a loop?
I'm moving from legacy IplImage * to new cv::Mat.
If I declare a Mat inside camera's loop, just to get a copy of current frame, will it alloc and release the memory storage at every run?
Thanks
no, it won't.
if you assign a cv::Mat to another like
Mat a=...; Mat b=a;
this will do a 'shallow' copy, both Mats will share the same dataso, even if you create a new Mat in the webcam loop, capture.read(frame) will just link it to whatever data is underneath.
And if I need some sort of temporary image, just to run a threshold or something like that, if I declare it inside the loop, will it be created and destroyed every time?
yes. different story. if you really care about that, declare them outside the loop, so they will get allocaed only once (unless you change the cam resolution, or similar)
but again, cv::Mat is a smartpointer, you do not leak any memory this way, we're only talking about allocation/deallocation costs, right ? (usually, you should not need to worry about this too much, unless you're on a really small box, like a raspi or smartphone)