apturing video from cameras or for reading video files and image sequences. Here is how the
class can be used: : VideoCapture类主要用于从相机中、视频文件中、相片序列中读取单帧图像。具体用法如下,图像序列只能为jpg格式
@code
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // 打开默认相机
if(!cap.isOpened()) // 检查操作是否成功
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // 从相机中抓取一帧图像
cvtColor(frame, edges, COLOR_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// 相机自动关闭
return 0;
}
/** @overload
@param filename name of the opened video file (eg. video.avi) or image sequence (eg.
img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...)
*/
CV_WRAP VideoCapture(const String& filename);
/** @overload
@param device id of the opened video capturing device (i.e. a camera index). If there is a single
camera connected, just pass 0. 相机序列号,0为默认设备
*/
CV_WRAP VideoCapture(int device);