使用Opencv视频读取(avi格式)
使用opencv读取视频,并显示
代码如下:
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
int main() {
std::string video_name = "./data/vtest.avi"; // The video path
cv::VideoCapture cap(video_name); // 使用CV里面的VideCapture ? 底层含义是什么?
if (!cap.isOpened()) { // 这里判断一下视频是否正常打开,如果打不开就会报错
std::cout << "Cannot open the video file" << std::endl;
return -1;
}
cv::Mat frame; // 定义一个Mat类型的数据frame,这个frame里面就包含了视频中的图像数据
while (cap.read(frame)) { // 如果这个视频没有被读完,就需要一直的进行读取
cv::imshow("video", frame); // 显示读取的视频
cv::waitKey(10);
}
cv::destroyAllWindows();
return 0;
}