天天看點

利用OpenCV讀取大華網絡攝像頭

項目需要将網絡攝像頭接入到伺服器上,用c++或者python處理每幀的圖像。查了很多資料總算解決了,回過頭發現是很小的問題,但是大華官網的SDK真的很難看懂。OpenCV2.4。

直接上代碼吧。

#include "cv.h"
#include "highgui.h"
#include <stdio.h>
using namespace std;
using namespace cv;

int main(int, char**) {
    VideoCapture vcap;
    Mat image;

    const string videoStreamAddress = "rtsp://admin:[email protected]/cam/realmonitor?channel=1&subtype=0";
    /* it may be an address of an mjpeg stream,
    e.g. "http://user:[email protected]_address:8081/cgi/mjpg/mjpg.cgi?.mjpg" */

    //open the video stream and make sure it's opened
    if(!vcap.open(videoStreamAddress)) {
        cout << "Error opening video stream or file" << endl;
        return -;
    }else{
       cout<<"success"<<endl;
    }

    //Create output window for displaying frames.
    //It's important to create this window outside of the `for` loop
    //Otherwise this window will be created automatically each time you call
    //`imshow(...)`, which is very inefficient.
    namedWindow("Output Window");
    for(;;) {
        if(!vcap.read(image)) {
            cout << "No frame" << endl;
            waitKey();
        }
        imshow("Output Window", image);
        if(waitKey() >= ) break;
    }
}
           

大華的網絡攝像頭編号:DH-IPC-HFW1225M-I1-0600B,用的是RTSP協定。

“rtsp://admin:[email protected]/cam/realmonitor?channel=1&subtype=0”;

其中的admin,dahua是登入攝像頭的使用者名和密碼。IP位址是192.168.1.108,可以根據具體情況修改。