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 72
|
#include "main.h"
using namespace cv;
using namespace std;
#include <iostream>
using namespace std;
char key;
int main()
{
IplImage *frame = NULL; //Preparing frame pointer
int key;
//Allocates and initializes cvCapture structure
// for reading a video stream from the camera.
//Index of camera is -1 since only one camera
// connected to the computer or it does not
// matter what camera to use.
CvCapture *input_camera = cvCaptureFromCAM(-1);
if(input_camera)
{
//Grabs and returns a frame from camera
frame = cvQueryFrame(input_camera);
//Creates window for displaying the frames
//Flag is reset (0) --> change window size
// manually
cvNamedWindow("Capturing Image", 0);
//Change to the appropriate size. In GTK, the
// inappropriate size will return a segmentation
// fault. I don't know why ...
//Gets the appropriate size using cvGetCaptureProperty
// with CV_CAP_PROP_FRAME_HEIGHT and CV_CAP_PROP_FRAME_WIDTH
// as property_id
cvResizeWindow("Capturing Image",
(int) cvGetCaptureProperty(input_camera, CV_CAP_PROP_FRAME_HEIGHT),
(int) cvGetCaptureProperty(input_camera, CV_CAP_PROP_FRAME_WIDTH));
while(frame != NULL)
{
//Shows a frame
cvShowImage("Capturing Image", frame);
//Checks if ESC is pressed and gives a delay
// so that the frame can be displayed properly
key = cvWaitKey(10);
if(key == 27)
break;
//Grabs and returns the next frame
frame = cvQueryFrame(input_camera);
}
//Release cvCapture structure
cvReleaseCapture(&input_camera);
//Destroy the window
cvDestroyWindow("Capturing Image");
}
else
{
cout << "Video stream not found\n\n";
}
cvWaitKey(0);
return 0;
} |
Partager