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

#include 
#include 
#include 
#include 
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;
}

 

你可能感兴趣的:(opencv,rtsp,视频流,多线程,rtsp,opencv)