Created
July 2, 2011 00:13
-
-
Save vo/1059618 to your computer and use it in GitHub Desktop.
Capture Image to Disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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