利用OpenCV和OpenMP的多路视频融合显示

来源:互联网 发布:java 跨行字符串 编辑:程序博客网 时间:2024/06/06 19:13

#include "stdafx.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "omp.h"

#define CAM_NUM 16//32路太多,w32不行,x64可以
using namespace cv;

int _tmain(int argc, _TCHAR* argv[])
{
Mat img;
VideoCapture vc[CAM_NUM];
int i;
string str;
int left;
int top;
bool run = true;
TickMeter tm;
int count = 0;


#pragma omp parallel for private(str)
for(i=0; i<CAM_NUM; i++)
{
if(i < 16)
str = format("rtsp://xx:xx@1xx.xx.xx.xx/h264/ch%d/sub/av_stream", i+1);
else if(i < 32)
str = format("rtsp://xx:xx@xx.xx.xx.xx/h264/ch%d/sub/av_stream", i-15);
else if(i < 48)
str = format("rtsp://xx:xx@xx.xx.xx.xx/h264/ch%d/sub/av_stream", i-31);
else
str = format("rtsp://xx:xx@xx.xx.xx.xx/h264/ch%d/sub/av_stream", i-47);
vc[i].open(str);
printf("Cam%d opened.\n", i);
}

int width = vc[0].get(CV_CAP_PROP_FRAME_WIDTH);
int height = vc[0].get(CV_CAP_PROP_FRAME_HEIGHT);
Mat imgShow(height * 8, width * 8, CV_8UC3);
//height /= 8;
//width /= 8;




while(run)
{
#pragma omp parallel for private(img, left, top)
for(i=0; i<CAM_NUM+1; i++)
{
if(i < CAM_NUM)
{
vc[i] >> img;
//resize(img, img, Size(), 0.125, 0.125);
left = i % 8 * width;
top = i / 8 * height;
img.copyTo(imgShow(Rect(left, top, width, height)));
}
else
{
namedWindow("Image");
imshow("Image", imgShow);
if (waitKey(1) == 27)
run = false;
tm.stop();
if (count++ % 25 == 0)
printf("time cost = %.1f\n", tm.getTimeMilli());
tm.reset();
tm.start();
}
}
}
return 0;
}



0 0
原创粉丝点击