Merge branch 'master' of https://github.com/szmoore/MCTX3420.git
[matches/MCTX3420.git] / server / stream.c
1 #include "cv.h"
2 #include "highgui_c.h"
3 #include <string.h>
4 #include <stdio.h>
5
6 /*-------------------------------------------------------------------
7
8 compile with:
9 -I/usr/include/opencv -I/usr/include/opencv2/highgui -L/usr/lib -lopencv_highgui -lopencv_core -lopencv_ml -lopencv_imgproc
10
11 --------------------------------------------------------------------*/
12
13 int storeFrame( CvCapture* capture)
14 {
15         IplImage *frame;
16         
17         int p[3];
18         p[0] = CV_IMWRITE_JPEG_QUALITY;
19         p[1] = 10;      //quality value. 0-100
20         p[2] = 0;
21                 
22         frame = cvQueryFrame(capture);
23         if( frame == NULL)
24                 return 0;       //error
25         cvSaveImage("images/test.JPG",frame,p);
26         return 1;
27 }
28
29 int main (int argc, char** argv)
30 {
31         CvCapture* capture;
32         
33         //Get capture structure for camera, -1 refers to any camera device.
34         //If multiple cameras used, need to use specific camera ID
35         capture = cvCreateCameraCapture(-1);
36         //If cvCreateCameraCapture returns NULL there is an error with the camera
37         if( capture == NULL)
38                 return -1;
39
40         while(1)
41         {
42                 if( !storeFrame( capture))
43                         return -1;
44                 //sleep(1);     //for now just to make the camera take 1 shot a second, as that's all my camera seems to be able to take/save (camera or function causing this? is 1 second per frame enough?)
45         }
46         
47         //Need to determine how the function is called in respect to system. just leave it running with a while loop? will something turn it on and off? will the function be called once from elsewhere?
48
49         cvReleaseCapture( &capture);
50 }
51

UCC git Repository :: git.ucc.asn.au