簡體   English   中英

通過OpenCV和C ++從IP攝像機流式傳輸視頻

[英]Streaming video from ip camera by opencv and c++

我正在嘗試使用OpenCV代碼從C ++訪問網絡攝像頭流,但是它失敗並顯示無法打開流的錯誤。 將URL替換為0時,下面提到的代碼將訪問網絡攝像頭。可通過VLC和python代碼訪問同一攝像機。

#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>

int main(int, char**) {

    VideoCapture cap("rtsp://admin:admin@10.11.18.185:554/cam/realmonitor?channel=1&subtype=0"); // open the video camera using http protocol with the URL specified 
    while (!cap.isOpened())  // if not success, exit program
    {
        cout << "cap not open" << endl;
        continue;
        //return -1;
    }

    Mat frame;
    namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); 
    while (1) {
        cap.read(frame);

        imshow("MyVideo", frame);
        if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
        {
            cout << "esc key is pressed by user" << endl;
            exit(0);
        }
    }
}

VideoCapture庫要求使用特定的格式集來接收視頻流。

從保存的文件中讀取文件時,我們在文件擴展名.mp4.avi等中指定相同的名稱。如果未指定此擴展名,VideoCapture將無法捕獲幀。

嘗試使用:

VideoCapture cap("rtsp://admin:admin@10.11.18.185:554/cam/realmonitor?channel=1&subtype=0/video?x.mjpeg");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM