opencv、c++、Qt连续截取双目摄像头画面

双目标定前,尝试获取双目相机的图像,但是所得图像是两个摄像头的画面相连而成的。
若出现select timeout ,则把摄像头拔开重新接入再运行程序即可。

#include <iostream>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <stdio.h>
using namespace std;
using namespace cv;

int main()
{
    VideoCapture capture(0); // 双目摄像头index为0
    Mat cam; 
    int i = 0;
    char filename[10];
    char c = 0;
    while (capture.read(cam))  			//capture >> cam
    {
        imshow("camwindow",cam); //窗口显示
        c = cvWaitKey(10);
        if (c == 'c') //连续按c键截取摄像头画面,默认保存在工程编译目录下
        {
        	sprintf(filename, "img%d.jpg",i++); //图片命名img0.jpg , img1.jpg... 
       		imwrite(filename, cam);
        }
        c = cvWaitKey(10);
        if (c == 27) //退出 ,27为Esc键
        {
             break;
        }
    }
    return 0;
}

在这里插入图片描述在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/MoonShapedPool/article/details/83094794