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] = 50;      //quality value. 0-100
20         p[2] = 0;
21                 
22         frame = cvQueryFrame(capture);
23         if( frame == NULL)
24                 return 0;       //error
25         cvSaveImage("../web/images/test.JPG",frame,p);
26         cvReleaseImageHeader(&frame);
27         return 1;
28 }
29
30 int main (int argc, char** argv)
31 {
32         CvCapture* capture;
33         
34         //Get capture structure for camera, -1 refers to any camera device.
35         //If multiple cameras used, need to use specific camera ID
36         capture = cvCreateCameraCapture(-1);
37         //If cvCreateCameraCapture returns NULL there is an error with the camera
38         if( capture == NULL)
39                 return -1;
40
41         while(1)
42         {
43                 if( !storeFrame( capture))
44                         return -1;
45                 //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?)
46         }
47         
48         //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?
49
50         cvReleaseCapture( &capture);
51 }
52

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