OpenCV通过VideoCapture类,来对视频进行读取,调用摄像头
读取视频:
1.先实例化再初始化
VideoCapture capture;
Capture.open("1.avi");
2.实例化的同时进行初始化
VideoCapture capture("1.avi");
播放视频:
视频读如到VideoCapture类对象之后,用一个循环将每一帧显示出来
while(1)
{
Mat frame;
capture>>frame;
imshow("读取视频",frame);
waitkey(30);
}
调用摄像头
将代码VideoCapture capture("1.avi")中的1.avi换成0就可以了
下面来看一段代码:
#include
using namespace cv;
using namespace std;
int main()
{
//读取视频或摄像头
VideoCapture capture("1.avi");
while (true)
{
Mat frame;
capture >> frame;
imshow("读取视频", frame);
waitKey(30);//延时30
}
return 0;
这是读取文件然后进行播放:
下面是运行结果:
下面看看工程目录的图
下面是打开摄像头的代码:
#include
using namespace cv;
using namespace std;
int main()
{
//读取视频或摄像头
VideoCapture capture(0);
while (true)
{
Mat frame;
capture >> frame;
imshow("读取视频", frame);
waitKey(30);//延时30
}
return 0;
}
运行结果:
最后
以上就是动人冬瓜最近收集整理的关于c 语言 调用电脑摄像头,C/C++ OpenCV读取视频与调用摄像头的全部内容,更多相关c内容请搜索靠谱客的其他文章。
发表评论 取消回复