test-opencv-memleak.c

Test opencv v4l memleak - Georg Engstrand, 2011-12-15 09:22 am

Download (1.3 kB)

 
1
#include </usr/include/opencv/cv.h>
2
#include </usr/include/opencv/highgui.h>
3
#include </usr/include/opencv/cxcore.h>
4
#include "stdio.h"
5
#include "string.h"
6
7
8
#define imageHeight_default 240
9
#define imageWidth_default 320
10
11
12
int main(int argc, char ** argv)
13
{
14
        CvCapture * pCapture_R;
15
        IplImage *pFrame_R;
16
17
        int imageWidth = imageWidth_default;
18
        int imageHeight = imageHeight_default;
19
20
        pCapture_R = cvCaptureFromCAM (0);
21
22
        int numOfCycles = 0;
23
24
        while (1)
25
        {
26
                int count = 0;
27
28
                printf("Capturing frames\n");
29
                while (count < 10)
30
                {
31
                        pFrame_R = cvQueryFrame( pCapture_R );
32
33
                        if( !pFrame_R ) fprintf(stderr, "failed to get a frame R\n");
34
                        int key = cvWaitKey(500);
35
                        count++;
36
                }
37
                
38
                printf("Done capturing frames\n");
39
40
                //calculating new resolution
41
                //following code changes the resulotion back and forth between 160x120 and 320x240
42
                if(imageHeight == 240)
43
                {
44
                        imageHeight /= 2;
45
                        imageWidth /= 2;
46
                        printf("New resolution: %dx%d\n", imageWidth, imageHeight );
47
                }
48
                else
49
                {
50
                        imageWidth *= 2;
51
                        imageHeight *= 2;
52
                        printf("New resolution: %dx%d\n", imageWidth, imageHeight );
53
                }
54
55
                //Changing resolution
56
                printf("changing resolution\n");
57
                cvSetCaptureProperty(pCapture_R, CV_CAP_PROP_FRAME_WIDTH, imageWidth );
58
                cvSetCaptureProperty(pCapture_R, CV_CAP_PROP_FRAME_HEIGHT, imageHeight );
59
60
                sleep(1);
61
        }
62
        return 0;
63
}