opencv 3.4.2 user memory leak

asked 2018-12-26 04:18:05 -0600

nobot gravatar image

i am using opencv 3.4.2, i wanted to know that if in an infinite for loop i keep on capturing images using a Mat variable frame, and after that if I do some other stuffs with that frame (like adding gaussian blur or canny filter) and save ultimately in frame, will that result into some uninitilalized memory ??

using namespace std; using namespace cv;

int main(int argc, char** argv ) {

UMat frame,gray;
VideoCapture cap(0);
    return -1;
for(;;) //////////////////////////////////////////////////////////////////////////
 cap >> frame; // get a new frame from camera

cvtColor(frame, gray, COLOR_BGR2GRAY);
GaussianBlur(gray, frame,Size(3, 3), 1.5);/////////////////////////////////////////
Canny(frame, frame, 0, 50);///// here the frame containing gaussianblur will be replaced by canny (i.e in the same memory location there will be canny frame) or the frame will be now pointing to another memory location(for canny frame), but the gaussianblur will be still there in heap memory?? 

imshow("canny", frame);
//imshow("frame", frame);
if (waitKey(30) == 27) 
        cout << "esc key is pressed by user" << endl;


return 0;


edit retag flag offensive close merge delete


when using UMat's you should not do operations in-place. please use a new UMat header for the results

berak gravatar imageberak ( 2018-12-26 04:32:27 -0600 )edit

i would like to known that if i am doing some inplace operation in UMat, will that result into some intermediate outputs , that will be there in the memory but not accessible??

nobot gravatar imagenobot ( 2018-12-26 04:38:30 -0600 )edit

don't use the same UMat for src and dst.

berak gravatar imageberak ( 2018-12-26 04:40:11 -0600 )edit

and the same is valid for Mat also??

nobot gravatar imagenobot ( 2018-12-26 04:41:41 -0600 )edit