建设工程查询扣分网站云点wordpress
- 操作系统:ubuntu22.04
 - OpenCV版本:OpenCV4.9
 - IDE:Visual Studio Code
 - 编程语言:C++11
 
算法描述
用于从视频文件、图像序列或摄像头捕获视频的类。
 该类提供了用于从摄像头捕获视频或读取视频文件和图像序列的 C++ API。
 以下是该类的使用方法:
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int, char**)
{Mat frame;//--- INITIALIZE VIDEOCAPTUREVideoCapture cap;// open the default camera using default API// cap.open(0);// OR advance usage: select any API backendint deviceID = 0;             // 0 = open default cameraint apiID = cv::CAP_ANY;      // 0 = autodetect default API// open selected camera using selected APIcap.open(deviceID, apiID);// check if we succeededif (!cap.isOpened()) {cerr << "ERROR! Unable to open camera\n";return -1;}//--- GRAB AND WRITE LOOPcout << "Start grabbing" << endl<< "Press any key to terminate" << endl;for (;;){// wait for a new frame from camera and store it into 'frame'cap.read(frame);// check if we succeededif (frame.empty()) {cerr << "ERROR! blank frame grabbed\n";break;}// show live and wait for a key with timeout long enough to show imagesimshow("Live", frame);if (waitKey(5) >= 0)break;}// the camera will be deinitialized automatically in VideoCapture destructorreturn 0;
}
 
注意
 在 C API 中,使用黑盒结构 CvCapture 代替 VideoCapture。
- (C++) 使用 
VideoCapture接口的基本示例可以在OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.cpp找到。 - (Python) 使用 
VideoCapture接口的基本示例可以在OPENCV_SOURCE_CODE/samples/python/video.py找到。 - (Python) 多线程视频处理的示例可以在 
OPENCV_SOURCE_CODE/samples/python/video_threaded.py找到。 - (Python) 展示 
Video4Linux2后端部分特性的VideoCapture示例可以在OPENCV_SOURCE_CODE/samples/python/video_v4l2.py找到。 
构造函数1
默认构造函数
cv::VideoCapture::VideoCapture	(		)	
 
构造函数2
使用 API 优先级打开视频文件、捕获设备或 IP 视频流以进行视频捕获。
 这是一个重载成员函数,为方便而提供。它与上述函数的不同之处仅在于它接受的参数
cv::VideoCapture::VideoCapture	
(const String & 	filename,int 	apiPreference = CAP_ANY 
)	
 
参数2
- 参数filename 它可以是: 
- 视频文件的名称(例如,video.avi)
 - 图像序列(例如,img_%02d.jpg,这将读取如 img_00.jpg、img_01.jpg、img_02.jpg 等样的样本)
 - 视频流的 URL(例如,protocol://host:port/script_name?script_params|auth)
 - 在使用 GStreamer 作为后端的情况下,GStreamer pipeline 字符串(gst-launch 工具格式)。请注意,每个视频流或 IP 摄像头馈送都有自己的 URL 方案。请参考源流的文档以了解正确的 URL。
 
 - 参数apiPreference 首选的捕获 API 后端。可以在多个可用的情况下强制使用特定的读取器实现:例如,cv::CAP_FFMPEG 或 cv::CAP_IMAGES 或 cv::CAP_DSHOW。
 
构造函数3
使用 API 优先级和参数打开视频文件、捕获设备或 IP 视频流以进行视频捕获。
 这是一个重载成员函数,为方便而提供。它与上述函数的不同之处仅在于它接受的参数。params 参数允许指定以成对形式编码的额外参数.(paramId_1, paramValue_1, paramId_2, paramValue_2, …)。参见 [cv::VideoCaptureProperties](https://docs.opencv.org/4.9.0/d4/d15/group__videoio__flags__base.html#gaeb8dd9c89c10a5c63c139bf7c4f5704d)。
cv::VideoCapture::VideoCapture	
(const String & 	filename,int 	apiPreference,const std::vector< int > & 	params 
)	
 
构造函数4
打开摄像头以进行视频捕获。
 这是一个重载成员函数,为方便而提供。它与上述函数的不同之处仅在于它接受的参数。
cv::VideoCapture::VideoCapture
(int 	index,int 	apiPreference = CAP_ANY 
)		
 
参数4
- 参数index 要打开的视频捕获设备的 ID。为了使用默认后端打开默认摄像头,只需传递 0。(为了向后兼容,在 apiPreference 为 CAP_ANY 时,使用 camera_id + domain_offset (CAP_*) 是有效的)
 - 参数apiPreference 首选的捕获 API 后端。可以在多个可用的情况下强制使用特定的读取器实现:例如,cv::CAP_DSHOW 或 cv::CAP_MSMF 或 cv::CAP_V4L。
 
构造函数5
使用 API 优先级和参数打开摄像头以进行视频捕获。
 这是一个重载成员函数,为方便而提供。它与上述函数的不同之处仅在于它接受的参数。params 参数允许指定以成对形式编码的额外参数(paramId_1, paramValue_1, paramId_2, paramValue_2, …)。参见 cv::VideoCaptureProperties。
cv::VideoCapture::VideoCapture
(int 	index,int 	apiPreference,const std::vector< int > & 	params 
)	
