From f95c1efcf706c2ca2e65e42114a62563ebeda555 Mon Sep 17 00:00:00 2001 From: Callum Date: Sun, 25 Aug 2013 16:14:23 +0800 Subject: [PATCH] function for takingand saving images --- camera/.capture.c.swp | Bin 0 -> 12288 bytes camera/capture.c | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 camera/.capture.c.swp create mode 100644 camera/capture.c diff --git a/camera/.capture.c.swp b/camera/.capture.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..9d8f11f90335299edf666012351d731029494a85 GIT binary patch literal 12288 zcmeI2&x;&I6vr!~#EHfgy~Km?GGUY1+4-3jVwl}5aTAvbNyx8_N(f_5PxW-g{xNh_ z&$@=hvt9)M0R{aFya=AWZv3Hky08u|kI z1WKV88ba?v1LzdA3LS$Mp`V`<;!Ef*v;w^fy$CHp`=Q?s2yq|!4!Q>&fc8VrKyM(< z)6fyTIOGcCiL22^P z>_a)5JxzS9DobOMk(S$`%;dVLhzi22=t#;*t-I7iNI{xWf*|a=u+G?fPuhrz3z}rO z-6b8S1`E{EPm@uDJPjMq9MgnYDc-@Xe4P{TWsFxTVIkfSvEY$Cv^57@E3Gi)oR{zA z+Qt_uz0UM7mz{(r5@s3vl1$Qk9Ih{6>6J`c63uQ8Efv)0ur_HX-()a%PH%QCh{qXzic<)tbmgIbobfMoqx37^^AQ63COX_Ru1( zDitWdG@P zAM`K0b)|pp?BLv`vzvpm1VL#>!2u3Y|(&i}>4|b%N(K2;Ub~=0B z#Mtk6vA1{R?bylZ9>O%w_8O^VPY*U0FLX9FutX^iD{j}0X5KbG%nWvSaB*#2?O)uq zIj8z8pXA$}p|NAf6nLoH*1SwdGT`$O1ho1; z7rcKgZ}gO-c!d^tF|63m@L;pe=`QM?OicAzm_7LB=UsaOhnPV%^SR^aS%xd>g@r;w z3O)mz%>@v73CvIt2|dLJhiJwn~_TQcA-qi5A{_;H4ewQ8u+cS`e1a`pK|*zzPN-m literal 0 HcmV?d00001 diff --git a/camera/capture.c b/camera/capture.c new file mode 100644 index 0000000..815cef0 --- /dev/null +++ b/camera/capture.c @@ -0,0 +1,59 @@ +#include "cv.h" +#include "highgui_c.h" +#include +#include +#include + +int storeFrame( CvCapture* capture) +{ + IplImage *frame; + time_t rawtime; // time given in seconds since jan 1st 1970 + struct tm *timeInfo;// time structure containing current time info + int buf = 100; + char timestamp[buf]; + char filepath[buf]; // filepath to save the image to + + //USING char *filepath creates seg fault. need to define bufsize, how big? + + time(&rawtime); + timeInfo = localtime(&rawtime); + 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); + snprintf(filepath,buf-1,"images/image_%s.JPG",timestamp); + + /*int p[3]; + p[0] = CV_IMWRITE_JPEG_QUALITY; + p[1] = 10; + p[2] = 0;*/ + + frame = cvQueryFrame(capture); + if( frame == NULL) + return 0; //error + cvSaveImage(filepath,frame,0); + + return 1; +} + +int main (int argc, char** argv) +{ + CvCapture* capture; + + //Get capture structure for camera, -1 refers to any camera device. + //If multiple cameras used, need to use specific camera ID + capture = cvCreateCameraCapture(-1); + //If cvCreateCameraCapture returns NULL there is an error with the camera + if( capture == NULL) + return -1; + + int i; + for( i=0;i<10;i++) + { + if( !storeFrame( capture)) + return -1; + 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?) + } + + //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? + + cvReleaseCapture( &capture); +} + -- 2.20.1