ONVIF(Open Network Video Interface Forum,開放式網路視訊介面論壇)是目前監控產業的重要國際標準,採用統一開放的標準作為網路攝影機、影像伺服器、門禁設備及中央管理系統之溝通協定。 OpenCV 的 VideoCapture 可支援 rtsp 協定的讀取, url 格式為:

    rtsp://username:password@ip:port/profile

程式 main.cpp 將讀取的影像放入 Mat, 可另做影像處理, 程式碼如下:

#include <stdio.h>

#include <iostream>

#include <opencv2/opencv.hpp>

#include <Windows.h>

 

using namespace std;

using namespace cv;

 

int main(int, char**)

{

     VideoCapture vcap;

     Mat image;   

     const string url  = "rtsp://admin:123456@192.168.1.13:8554/profile0";

 

     //open the video stream and make sure it's opened   

     if (!vcap.open(url))

     {

         cout << "Error opening video stream or file" << endl;

         return -1;

     }

 

     float scale = 2;

     while (vcap.read(image) && waitKey(1)<0)

     {

         namedWindow("image", WINDOW_NORMAL);

         resizeWindow("image", 1920 / scale, 1080 / scale);

         imshow("image", image);

     }

 

}

arrow
arrow
    文章標籤
    OpenCV
    全站熱搜

    ghostyguo 發表在 痞客邦 留言(0) 人氣()