前端设计模板,周口网站seo,惠州行业网站设计方案,凡科网门店通一、知识点 1、VideoCapture类 (1)、用于从视频文件、摄像机或图像序列中捕获视频帧。 (2)、构造函数 VideoCapture(const String filename, int apiPreference CAP_ANY) a、filename可以是视频文件的名称(例如video.avi)#xff0c;可以是图…一、知识点 1、VideoCapture类 (1)、用于从视频文件、摄像机或图像序列中捕获视频帧。 (2)、构造函数 VideoCapture(const String filename, int apiPreference CAP_ANY) a、filename可以是视频文件的名称(例如video.avi)可以是图像序列(例如img%02.jpg, 它将读取img00.jpg、img01.jpg、img02.jpg等)还可以是URL。 b、apiPreference是实际执行捕获的API后端VideoCaptureAPIs枚举值如: CAP_ANY、CAP_FFMPEG、CAP_IMAGES等。 (3)、构造函数 VideoCapture(int index, int apiPreference CAP_ANY) a、打开摄像头进行视频拍摄。 b、index是视频捕获设备的索引默认摄像头传递0。 c、apiPreference是实际执行捕获的API后端VideoCaptureAPIs枚举值如: CAP_ANY、CAP_FFMPEG、CAP_IMAGES等。 (4)、成员函数 virtual bool read(OutputArray image) a、抓取、解码并返回一个视频帧。 b、image为返回的视频帧。 如果没有抓取任何帧则图像为空返回false。 (5)、成员函数 virtual void release(); a、关闭视频文件或捕获设备。 二、示例代码
#include iostream
#include opencv2/opencv.hppint main()
{cv::VideoCapture capture(../images/video.mp4);cv::Mat frame;while (true){capture.read(frame);if (frame.empty()){break;}//此处可以对frame做各种处理...cv::imshow(frame sequence, frame);int c cv::waitKey(1);if (c 27){break;}}capture.release();system(pause);return 0;
} 下一章讲解视频处理与保存。