本文主要是介绍OpenCV编程-四路摄像头拼接实时显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
手头上摄像头蛮多的,顺便就把多路摄像头实时拼接显示做了一下,如下图:
// opencvtest.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
#include <time.h>
#include<windows.h>
using namespace cv;
using namespace std;Mat frame;
Mat frame1;
Mat b;
Mat b1;
cv::Mat roi_img_left;
cv::Mat roi_img_right;
cv::Mat roi_img_left1;
cv::Mat roi_img_right1;
char fileNameBmpLeft[64];
char fileNameBmpRight[64];
int calibStep = 1;
int ret = 0;
int _tmain(int argc, _TCHAR* argv[])
{namedWindow("【display】", CV_WINDOW_NORMAL);VideoCapture capture(1);Sleep(100);capture.set(CV_CAP_PROP_FRAME_WIDTH, 2560);capture.set(CV_CAP_PROP_FRAME_HEIGHT, 960);capture.set(CV_CAP_PROP_FPS, 30);//帧数Sleep(100);VideoCapture capture1(2);Sleep(100);capture1.set(CV_CAP_PROP_FRAME_WIDTH, 2560);capture1.set(CV_CAP_PROP_FRAME_HEIGHT, 960);capture1.set(CV_CAP_PROP_FPS, 30);//帧数Sleep(100);setMouseCallback("【display】", on_mouse, &frame);while (1){capture1 >> frame1;capture >> frame;b = frame.clone(); //a copy to b roi_img_left = frame(cv::Range(0, 960), cv::Range(0, 1280));roi_img_right = b(cv::Range(0, 960), cv::Range(1280, 2560));b1 = frame1.clone(); //a copy to b roi_img_left1 = frame1(cv::Range(0, 960), cv::Range(0, 1280));roi_img_right1 = b1(cv::Range(0, 960), cv::Range(1280, 2560));Mat combine, combine1, combine2;hconcat(roi_img_left, roi_img_right, combine1);hconcat(roi_img_left1, roi_img_right1, combine2);vconcat(combine1, combine2, combine);imshow("【display】", combine);frame.release();break;waitKey(30);}capture.release();system("pause");return 0;
}
这篇关于OpenCV编程-四路摄像头拼接实时显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!