Go to the documentation of this file.00001
00002
00003 #include <assert.h>
00004 #include <ctype.h>
00005
00006 #include <opencv2/highgui/highgui_c.h>
00007
00008 #include "CV.hpp"
00009 #include "File.hpp"
00010 #include "String.hpp"
00011
00019
00020 int main(int arguments_size, char * arguments[]) {
00021 CvCapture * capture = NULL;
00022 String_Const capture_base_name = "video_capture";
00023
00024 if (arguments_size <= 1) {
00025
00026 File__format(stderr,
00027 "Usage: Video_Capture camera_number [capture_base_name]\n");
00028 return 1;
00029 } else {
00030
00031 String argument1 = arguments[1];
00032 if (arguments_size > 2) {
00033 capture_base_name = arguments[2];
00034 }
00035
00036
00037 if (isdigit(argument1[0])) {
00038
00039 unsigned int camera_number = String__to_unsigned(argument1);
00040 int camera_flags = CV_CAP_ANY + (int)camera_number;
00041 capture = cvCreateCameraCapture(camera_flags);
00042 if (capture == NULL) {
00043 File__format(stderr,
00044 "Could not open camara %d\n", camera_number);
00045 return 1;
00046 }
00047
00048
00049 cvSetCaptureProperty(capture,
00050 CV_CAP_PROP_FRAME_WIDTH, (double)640);
00051 cvSetCaptureProperty(capture,
00052 CV_CAP_PROP_FRAME_HEIGHT, (double)480);
00053 } else {
00054
00055 capture = cvCreateFileCapture(argument1);
00056 if (capture == NULL) {
00057 File__format(stderr,
00058 "Could not open video file '%s'\n", argument1);
00059 return 1;
00060 }
00061 }
00062 }
00063
00064 assert(capture != NULL);
00065
00066
00067 String_Const window_name = "Video_Capture";
00068 cvNamedWindow(window_name, CV__window_auto_size);
00069
00070
00071 unsigned int capture_number = 0;
00072 while (1) {
00073
00074 CV_Image frame = cvQueryFrame(capture);
00075 if (frame == (CV_Image)0) {
00076
00077
00078 break;
00079 }
00080
00081
00082 cvShowImage(window_name, frame);
00083
00084
00085 char character = cvWaitKey(33);
00086 if (character == '\033') {
00087
00088 break;
00089 } else if (character == ' ') {
00090
00091 String file_name =
00092 String__format("%s-%02d.pnm", capture_base_name, capture_number);
00093 CV_Image__pnm_write(frame, file_name);
00094 File__format(stderr, "Wrote frame out to file '%s'\n", file_name);
00095 capture_number += 1;
00096 String__free(file_name);
00097 }
00098 }
00099
00100
00101 cvReleaseCapture(&capture);
00102 cvDestroyWindow(window_name);
00103
00104 return 0;
00105 }