opencv 学习记录2 读取视频和摄像头

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

// OpenCV includes opencv提供的跨平台io函数
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;

// OpenCV command line parser functions
// Keys accecpted by command line parser
const char* keys =
{
	"{help h usage ? | | print this message}"
	"{@video | | Video file, if not defined try to use webcamera}"
};

int main(int argc, const char** argv)
{

	VideoCapture cap; 
	// 读取视频。open的参数为0时,会读取摄像头
	cap.open("D:\\opencvStudy\\123.mp4");
	//if (videoFile != "")
	//	cap.open(videoFile);
	//else
	//	cap.open(0);
	//检查读取是否成功
	if (!cap.isOpened())  
		return -1;

	//打开一个窗口 并命名为video
	namedWindow("Video", 1);

	//使用无限循环来显示帧
	for (;;)
	{
		Mat frame;
		//操作抓取帧
		cap >> frame;  
		if (frame.empty())
			return 0;
		//显示
		imshow("Video", frame);
		//等待30毫秒
		if (waitKey(30) >= 0) break;
	}
	//释放所有视频资源
	cap.release();

	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值