【OpenCV】OpenCV 读取摄像头数据

通过cv::VideoCapture类读取外接设备视频流(摄像头或外接读卡器获取到的视频流)

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
cv::VideoCapture capture(0);

if (!capture.isOpened())
{
printf("could not open camera...\n");
return -1;
}
cv::namedWindow("capture", WINDOW_AUTOSIZE);

cv::Mat frame;
int index = 0;

while (true)
{
if (!capture.read(frame))
break;

cv::imshow("capture", frame);
char c = waitKey(1);

if (c >= 49) {
index = c - 49;
}
if (c == 27) {
break;
}
}

capture.release();