This repository has been archived by the owner on Aug 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
liveimage.cc
71 lines (41 loc) · 1.71 KB
/
liveimage.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Example : grab and display a single live image
// usage: prog
// Author : Toby Breckon, [email protected]
// Copyright (c) 2006 School of Engineering, Cranfield University
// License : LGPL - http://www.gnu.org/licenses/lgpl.html
#include "cv.h" // open cv general include file
#include "highgui.h" // open cv GUI include file
#include <stdio.h>
int main( int argc, char** argv )
{
IplImage* img; // image object
char const * windowName = "OPENCV: live image display"; // window name
// create window object
cvNamedWindow(windowName, 1 );
// grab an image from camera (here assume only 1 camera, device #0)
CvCapture* capture = cvCaptureFromCAM(0); // capture from video device #0
// Add in the following 2 lines for Quickcam Express II on linux
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 240);
if(!cvGrabFrame(capture)){
printf("Could not grab a frame\n");
exit(0);
}
// cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);
// cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 160);
img=cvRetrieveFrame(capture); // retrieve the captured frame
// display image in window
cvShowImage( windowName, img );
// start event processing loop (very important,in fact essential for GUI)
cvWaitKey(0);
// destroy window object
// (triggered by event loop *only* window is closed)
cvDestroyWindow( windowName );
// release capture device
cvReleaseCapture(&capture);
// Note that the image captured by the device is allocated/released
// by the capture function.
// There is no need to release it explicitly.
// all OK : main returns 0
return 0;
}