Add reference to issues page when commenting about issue 6 (for reference in printed...
[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         CvMat* jpg;
17         
18         //FILE *fp = fopen ("test.jpg", "wb");
19
20         int p[3];
21         p[0] = CV_IMWRITE_JPEG_QUALITY;
22         p[1] = 100;     //quality value. 0-100
23         p[2] = 0;
24                 
25         frame = cvQueryFrame(capture);
26         if( frame == NULL)
27                 return 0;       //error
28         cvSaveImage("../web/images/test.JPG",frame,p);
29         //jpg = cvEncodeImage(".jpg", frame,p); 
30         /*pass buf to client, write to file on client*/
31         //fwrite(jpg->data.ptr,1,jpg->rows*jpg->cols, fp);
32         
33         //decjpg = cvDecodeImage(jpg, CV_LOAD_IMAGE_COLOR);
34         //cvShowImage( "Display window", decjpg );  
35                         
36         //cvWaitKey(0);
37         cvReleaseImageHeader(&frame);
38         //cvReleaseMat(&jpg);
39         //fclose( fp);
40         return 1;
41 }
42
43 int main (int argc, char** argv)
44 {
45         CvCapture* capture;
46         //cvNamedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
47         //Get capture structure for camera, -1 refers to any camera device.
48         //If multiple cameras used, need to use specific camera ID
49         capture = cvCreateCameraCapture(-1);
50         //If cvCreateCameraCapture returns NULL there is an error with the camera
51         if( capture == NULL)
52                 return -1;
53
54         cvSetCaptureProperty (capture, CV_CAP_PROP_FOURCC, 'MJPEG');
55
56         while(1)
57         {
58                 if( !storeFrame( capture))
59                         return -1;
60                 printf("enter to continue");
61                 getchar();
62                 //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?)
63         }
64         
65         //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?
66         cvReleaseCapture( &capture);
67 }
68

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