opencv视频基础操作

来源:互联网 发布:服务器主流软件 编辑:程序博客网 时间:2024/05/01 16:00

一.读取并播放视频:

   将视频“a.avi”放入工程目录下

   (1)VideoCapture capture("a.avi");

   (2)VideoCapture capture;

       capture.open("a.avi");

程序:

 #include<iostream>

#include<opencv2/opencv.hpp>

using namespace cv;

using namespace std;

int main()

{

VideoCapture capture ("a.avi");//读入视频

if(!capture.isOpened())//检查是否成功打开

{

cerr<<"Can't open a file"<<endl;

return -1;

}

namedWindow("video",1);

for(;;)

{

Mat frame;

capture>>frame;//从capture读一帧存到frame

if(frame.empty())//若未读到图像

    break;

imshow("video",frame);

if (waitKey(20)>=0)

   break;

}

return 0;

}

二.调用摄像头

  (1)VideoCapture capture(0);

   (2)VideoCapture capture;

       capture.open(0);


0 0