Windows7+opencv+vs2015+c/c++实现四个摄像头同时工作


    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);
最好按顺序从高到低排序

以下是使用OpenCV C++标定四个摄像头的示例代码: ```c++ #include <opencv2/calib3d.hpp> #include <opencv2/core.hpp> #include <opencv2/imgcodecs.hpp> #include <opencv2/highgui.hpp> #include <iostream> #include <vector> using namespace cv; using namespace std; int main() { int numBoards = 20; int numCornersHor = 9; int numCornersVer = 6; Size boardSize = Size(numCornersHor, numCornersVer); vector<vector<Point3f>> objectPoints; vector<vector<Point2f>> imagePoints; vector<Point2f> corners; int successes = 0; vector<Mat> images; Mat image; for (int i = 0; i < 4; i++) { for (int j = 1; j <= numBoards; j++) { string filename = "camera" + to_string(i) + "_" + to_string(j) + ".jpg"; image = imread(filename, IMREAD_GRAYSCALE); bool found = findChessboardCorners(image, boardSize, corners, CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_NORMALIZE_IMAGE); if (found) { cornerSubPix(image, corners, Size(11, 11), Size(-1, -1), TermCriteria(TermCriteria::EPS | TermCriteria::MAX_ITER, 30, 0.1)); drawChessboardCorners(image, boardSize, corners, found); imshow("Board", image); waitKey(100); imagePoints.push_back(corners); objectPoints.push_back(vector<Point3f>()); vector<Point3f> &opt = objectPoints.back(); for (int k = 0; k < numCornersHor * numCornersVer; k++) { opt.push_back(Point3f((float)(k / numCornersHor) * 25, (float)(k % numCornersHor) * 25, 0.0f)); } successes++; if (successes >= numBoards) { break; } } } } vector<Mat> rvecs, tvecs; vector<double> reprojErrs; double rms = calibrateCameraRO(objectPoints, imagePoints, boardSize, 0, 0, rvecs, tvecs); cout << "RMS: " << rms << endl; Mat cameraMatrix, distCoeffs; vector<Mat> rvecsMat, tvecsMat; for (int i = 0; i < 4; i++) { Mat rvec, tvec; calibrateCameraRO(objectPoints, imagePoints, boardSize, cameraMatrix, distCoeffs, rvec, tvec, i, 0); rvecsMat.push_back(rvec); tvecsMat.push_back(tvec); } cout << "Camera matrix: " << endl; cout << cameraMatrix << endl; cout << "Distortion coefficients: " << endl; cout << distCoeffs << endl; return 0; } ``` 上述代码使用了OpenCV中的`calibrateCameraRO`函数进行标定,并采用棋盘格进行标定。其中,`numBoards`表示采集的标定板数量,`numCornersHor`和`numCornersVer`分别表示棋盘格的水平和垂直角点数。通过对每个摄像头采集图像数据,并分别进行标定,最终得到了每个摄像头的内参矩阵和畸变系数。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值