Skip to content

Instantly share code, notes, and snippets.

@vo
Created July 2, 2011 00:13
Show Gist options
  • Save vo/1059618 to your computer and use it in GitHub Desktop.
Save vo/1059618 to your computer and use it in GitHub Desktop.
Capture Image to Disk
#include <cstdio>
#include <ctime>
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv) {
// open camera
cv::VideoCapture cap(0);
if(!cap.isOpened())
return -1;
// capture frame (captures 15 frames to settle)
cv::Mat frame;
for(int i=0; i<15; i++)
cap >> frame;
// write to disk with timestamp name
time_t t = time(NULL);
char * tstamp = ctime(&t);
tstamp[strlen(tstamp)-1] = '\0';
char filename[128];
sprintf(filename, "%s.jpg", tstamp);
imwrite(filename, frame);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment