Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Memory leak on webcam capture

Hello all, I am running a code in linux, C, part of a deep learning (YOLO) project and I am having problems with a memory leak omewhere related to opencv.

I am using 3 webcams in my project at the same time and placing the captures together side by side using the function:

cap = get_capture_webcam(1); cap2 = get_capture_webcam(2); cap3 = get_capture_webcam(3);

There is some memory leak in the code because after about 2 min it crashes and I have to restart it. I've tried releasing every image I use and I still can't find the leak.

Does anyone know common causes of leaks using this function or any other that I might be using?

Thanks in advance

Memory leak on webcam capture

Hello all, I am running a code in linux, C, part of a deep learning (YOLO) project and I am having problems with a memory leak omewhere related to opencv.

I am using 3 webcams in my project at the same time and placing the captures together side by side using the function:

cap = get_capture_webcam(1); cap2 = get_capture_webcam(2); cap3 = get_capture_webcam(3);

There is some memory leak in the code because after about 2 min it crashes and I have to restart it. I've tried releasing every image I use and I still can't find the leak.

Does anyone know common causes of leaks using this function or any other that I might be using?

Thanks in advance

Edit: Okay sorry. So this is the function that is causing the leak (I'm pretty sure)

int fill_image_from_stream2(CvCapture *cap, CvCapture *capi2, CvCapture *capi3, image im)
{
    IplImage* src = cvQueryFrame(cap);
 if (!src) return 0;
int w = src->width;
int h = src->height;

IplImage* src2 = cvQueryFrame(capi2);
if (!src2) return 0;
IplImage* src3 = cvQueryFrame(capi3);
if (!src3) return 0;
IplImage *imagem = cvCreateImage(cvSize(w*3,3*h/4), src->depth, src->nChannels);

cvSetImageROI(imagem, cvRect(0, 0, w, h));
cvSetImageROI(src, cvRect(0, h/4, w, 3*h/4));
    cvCopy(src,imagem, NULL);
    cvResetImageROI(src); 
    cvResetImageROI(imagem); 
cvSetImageROI(imagem, cvRect(w, 0, src2->width, src2->height));
cvSetImageROI(src2, cvRect(0, h/4, w, 3*h/4));
    cvCopy(src2,imagem, NULL);
    cvResetImageROI(src2); 
    cvResetImageROI(imagem);
cvSetImageROI(imagem, cvRect(w*2, 0, src3->width, src3->height));
cvSetImageROI(src3, cvRect(0, h/4, w, 3*h/4));
    cvCopy(src3,imagem, NULL);
    cvResetImageROI(src3); 
    cvResetImageROI(imagem);  
//image im2 = ipl_to_image(imagem);



    ipl_into_image(imagem, im);
    rgbgr_image(im);
imagem = 0;
src = 0;
src2 = 0;
src3 = 0;
    return 1;
}

It crashes after about 2000 frames.