1 | /* |
---|
2 | * TestCapture.cpp |
---|
3 | * OpenCV |
---|
4 | * |
---|
5 | */ |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | #include <cv.h> |
---|
10 | #include <cxcore.h> |
---|
11 | #include <highgui.h> |
---|
12 | #include <iostream> |
---|
13 | |
---|
14 | |
---|
15 | using namespace std; |
---|
16 | |
---|
17 | const char * WINDOW_NAME = "Playback" ; |
---|
18 | |
---|
19 | int usingCamera; |
---|
20 | |
---|
21 | int main (int argc, char * const argv[]) |
---|
22 | { |
---|
23 | int key=0; |
---|
24 | CvCapture* camera = NULL; |
---|
25 | |
---|
26 | if (argc < 2) { |
---|
27 | cout << "Getting Camera " << CV_CAP_ANY << endl; |
---|
28 | camera = cvCreateCameraCapture (CV_CAP_ANY); |
---|
29 | usingCamera = 1; |
---|
30 | } else { |
---|
31 | if (argv[1][0] == '-') { |
---|
32 | cout << "An simple program to display a video or camera output." << endl << endl |
---|
33 | << "Usage: " << endl << " >> TestCapture [optional-path-to-movie-file]" << endl << endl |
---|
34 | << "If no optional path to a movie file is provided, attempts to use an attached" << endl |
---|
35 | << " camera for input. Otherwise, attempts to use the movie file for input." << endl << endl; |
---|
36 | return 0; |
---|
37 | } |
---|
38 | cout << "Getting Movie " << argv[1] << endl; |
---|
39 | camera = cvCreateFileCapture(argv[1]); |
---|
40 | usingCamera = 0; |
---|
41 | } |
---|
42 | |
---|
43 | if (! camera) { |
---|
44 | cout << "Failed to get input from a video capture source." << endl << endl |
---|
45 | << "Usage: " << endl << " >> TestCapture [optional-path-to-movie-file]" << endl << endl |
---|
46 | << "If no optional path to a movie file is provided, attempts to use an attached" << endl |
---|
47 | << " camera for input. Otherwise, attempts to use the movie file for input." << endl << endl; |
---|
48 | return 0; |
---|
49 | } |
---|
50 | |
---|
51 | cvNamedWindow (WINDOW_NAME, CV_WINDOW_AUTOSIZE); |
---|
52 | |
---|
53 | IplImage * current_frame = cvQueryFrame (camera); |
---|
54 | |
---|
55 | while (key != 'q' && key != 'Q') { //Loop until user enters 'q' |
---|
56 | |
---|
57 | |
---|
58 | current_frame = cvQueryFrame (camera); |
---|
59 | |
---|
60 | if (current_frame==NULL) { //implies reached camera end |
---|
61 | cvSetCaptureProperty(camera, CV_CAP_PROP_POS_FRAMES, 0); //reset camera to beginning |
---|
62 | current_frame = cvQueryFrame (camera) ; |
---|
63 | if (current_frame==NULL) //shouldn't happen |
---|
64 | break; |
---|
65 | } |
---|
66 | |
---|
67 | cvShowImage(WINDOW_NAME, current_frame); |
---|
68 | } |
---|
69 | cvReleaseCapture(&camera); |
---|
70 | cvReleaseImage(¤t_frame); |
---|
71 | } |
---|