VideoCapture cap;
VideoCapture cap1;
VideoCapture cap2;
VideoCapture cap3;
//if (!cap.isOpened())
///{
// cout << "摄像头未打开" << endl;
//}
//Mat M;
//namedWindow("摄像头1", 1);
cvWaitKey(300);
Mat frame1,frame2,frame3,frame0;
bool bStop = false;
cap3.open(4);
cap2.open(2);
cap1.open(1);
cap.open(0);
//cap3.open(3);
while (!bStop) {
cap >> frame0;
cap1 >> frame1;
cap2 >> frame2;
cap3 >> frame3;
1.基本介绍
视频读取本质上就是读取图像,因为视频是由一帧一帧图像组成的。1秒24帧基本就能流畅的读取视频了。
①读取视频有两种方法:
VideoCapture cap;
cap.open(“1.avi”);
或VideoCapture cap(“1.avi”);
②循环显示每一帧:
while(1)
{
Mat frame; //定义Mat变量,用来存储每一帧
cap>>frame; //读取当前帧方法一
//cap.read(frame); //读取当前帧方法二
imshow(“视频显示”, frame); //显示一帧画面
waitKey(30); //延时30ms
}
2.注意
cvWaitKey(0);暂停(只处理一帧图像)
处理连续多帧图像时不加
3.格式转换mat->IplImage
IplImage* pBinary0 = &IplImage(frame0);
深拷贝只要再加一次复制数据:
IplImage *input0 = cvCloneImage(pBinary0);
4.usb控制器
效果图如下:
使用的是四个相同红外+白光免驱摄像头,其中有摄像头插入HUB上,没有PCI扩展,
cap3.open(4);
cap2.open(2);
cap1.open(1);
cap.open(0);
最好按顺序从高到低排序