利用OpenCV读取大华网络摄像头

项目需要将网络摄像头接入到服务器上,用c++或者python处理每帧的图像。查了很多资料总算解决了,回过头发现是很小的问题,但是大华官网的SDK真的很难看懂。OpenCV2.4。
直接上代码吧。

#include "cv.h"
#include "highgui.h"
#include 
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:pass@cam_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 -1;
    }else{
       cout<<"success"<//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(1) >= 0) break;
    }
}

大华的网络摄像头编号:DH-IPC-HFW1225M-I1-0600B,用的是RTSP协议。
“rtsp://admin:[email protected]/cam/realmonitor?channel=1&subtype=0”;
其中的admin,dahua是登录摄像头的用户名和密码。IP地址是192.168.1.108,可以根据具体情况修改。

你可能感兴趣的:(图像处理)