Brise

OpenCV로 웹캠 읽어오기 본문

프로그램

OpenCV로 웹캠 읽어오기

naudhizb 2015. 12. 17. 14:07
반응형


--



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
/////////////////////////////////////////////////////
// trialcam1a.cpp
// A Simple Camera Capture Framework
// This program will connect to a camera then
// show the frames in a window
/////////////////////////////////////////////////////
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
 
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); 
 
//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 ...");
 
return 0;
}
 
cs

--





반응형

'프로그램' 카테고리의 다른 글

OPC DA DCOM Configuration  (0) 2015.12.28
옛날 8비트 시절의 그래픽 구현 테크닉  (0) 2015.12.20
정보 보안 및 해킹 관련 사이트  (0) 2015.12.18
칼만필터  (0) 2015.04.21
B-spline  (0) 2014.11.07
부동소수점 변수의 정확도  (0) 2014.09.18
임베디드 통신  (0) 2014.09.17
Comments