利用opencv多线程读取多路rtsp视频流

#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <thread>
using namespace cv;
using namespace std;
Mat img=Mat(Size(1280,480),CV_8UC3);
void camera1()
{
 VideoCapture capture;
    Mat frame,FlipImg;
    string fileDir = "rtsp://admin:*****@192.168.***.****:554/h264/ch1/main/av_stream";
    capture.open(fileDir.c_str());

    if (!capture.isOpened()) {
        cout << "colud not load vodeo...." << endl;
        return;
    }
	while (capture.read(frame)) {
		resize(frame, frame, Size(640, 480));
		frame.copyTo(img(Rect(0,0,640,480)));
		imshow("img,", img);
       waitKey(2);
    }

}
void camera2(){

    Mat frame;
    VideoCapture capture;
    string fileDir = "rtsp://admin:*****@192.168.****.****:554/h264/ch1/main/av_stream";
    capture.open(fileDir.c_str());

    if (!capture.isOpened()) {
        cout << "colud not load vodeo...." << endl;
        return ;
    }

    while (capture.read(frame)) {
		resize(frame, frame, Size(640, 480));

	 frame.copyTo(img(Rect(640, 0, 640, 480)));
       waitKey(1);
    }
}
int main(int argc, char** argv) {
   
   std::thread cap1(camera1);
   cap1.detach();
   std::thread cap2(camera2);
   cap2.detach();
   while (1){
   }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值