CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 4042|回复: 0

Displaying the video feed from default camera device

[复制链接]
发表于 2014-3-3 16:52:30 | 显示全部楼层 |阅读模式
Displaying the video feed from default camera device
// Program to display a video from attached default camera device
// Author: Samarth Manoj Brahmbhatt, University of Pennsylvania
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
// 0 is the ID of the built-in laptop camera, change if you want to use other camera
VideoCapture cap(0);
//check if the file was opened properly
if(!cap.isOpened())
{
cout << "Capture could not be opened successfully" << endl;
return -1;
}
namedWindow("Video");
// Play the video in a loop till it ends
while(char(waitKey(1)) != 'q' && cap.isOpened())
{
Mat frame;
cap >> frame;
// Check if the video is over
if(frame.empty())
{
cout << "Video over" << endl;
break;
}
imshow("Video", frame);
}
return 0;
}
The code itself is self-explanatory, and I would like to touch on just a couple of lines.
VideoCapture cap(0);
This creates a VideoCapture object that is linked to device number 0 (default device) on your computer. And
cap >> frame;
extracts a frame from the device to which the VideoCapture object cap is linked. There are some other ways to extract
frames from camera devices, especially when you have multiple cameras and you want to synchronize
them (extract
frames from all of them at the same time). I shall introduce such methods in Chapter 10.
You can also give a file name to the VideoCapture constructor, and OpenCV will play the video in that file for you
exactly in the same manner (see Listing 4-5).
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-4-28 03:30 , Processed in 0.019872 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部