利用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:dahua@192.168.1.108/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"<<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(1) >= 0) break;
    }
}

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

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值