opencv2简单的视频读取

来源:互联网 发布:太阳系软件下载 编辑:程序博客网 时间:2024/05/19 05:40




#include "stdafx.h"#include <opencv2/core/core.hpp>#include <opencv2/core/mat.hpp>#include "cv.h"#include "highgui.h"#include "cxcore.h"#include <iostream>#include <stdio.h>using namespace cv;using namespace std;int main(int argc,char* argv[]){// Open the video filecv::VideoCapture capture("f:/1.rmvb");//要读取的视频文件// check if video successfully openedif (!capture.isOpened())return 1;// Get the frame ratedouble rate= capture.get(CV_CAP_PROP_FPS);bool stop(false);cv::Mat frame; // current video framecv::namedWindow("Extracted Frame");// Delay between each frame in ms// corresponds to video frame rateint delay= 1000/rate;// for all frames in videowhile (!stop) {// read next frame if anyif (!capture.read(frame))break;cv::imshow("Extracted Frame",frame);// introduce a delay// or press key to stopif (cv::waitKey(delay)>=0)stop= true;}// Close the video file.// Not required since called by destructorcapture.release();waitKey(3000);return 0;}


原创粉丝点击