Update Titlepage with links to individual sections
[matches/MCTX3420.git] / camera / capture.c
1 #include "cv.h"
2 #include "highgui_c.h"
3 #include <string.h>
4 #include <stdio.h>
5 #include <time.h>
6
7 int storeFrame( CvCapture* capture)
8 {
9         IplImage *frame;
10         time_t rawtime; // time given in seconds since jan 1st 1970
11         struct tm *timeInfo;// time structure containing current time info
12         int buf = 100;
13         char timestamp[buf];
14         char filepath[buf];     // filepath to save the image to
15
16         //USING char *filepath creates seg fault. need to define bufsize, how big?
17
18         time(&rawtime);
19         timeInfo = localtime(&rawtime);
20         snprintf(timestamp,buf-1,"%d.%d.%d_%d.%d.%d", timeInfo->tm_year + 1900, timeInfo->tm_mon + 1, timeInfo->tm_mday,timeInfo->tm_hour, timeInfo->tm_min, timeInfo->tm_sec);
21         snprintf(filepath,buf-1,"images/image_%s.JPG",timestamp);
22
23         /*int p[3];
24         p[0] = CV_IMWRITE_JPEG_QUALITY;
25         p[1] = 10;      //quality value; 0->100
26         p[2] = 0;*/
27                 
28         frame = cvQueryFrame(capture);
29         if( frame == NULL)
30                 return 0;       //error
31         cvSaveImage(filepath,frame,0);
32         cvReleaseImageHeader(&frame);
33         return 1;
34 }
35
36 int main (int argc, char** argv)
37 {
38         CvCapture* capture;
39         
40         //Get capture structure for camera, -1 refers to any camera device.
41         //If multiple cameras used, need to use specific camera ID
42         capture = cvCreateCameraCapture(-1);
43         //If cvCreateCameraCapture returns NULL there is an error with the camera
44         if( capture == NULL)
45                 return -1;
46
47         int i;
48         for( i=0;i<10;i++)
49         {
50                 if( !storeFrame( capture))
51                         return -1;
52                 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?)
53         }
54         
55         //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?
56
57         cvReleaseCapture( &capture);
58 }
59

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