您的位置:首页 > 理论基础 > 计算机网络

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

2016-07-21 16:45 736 查看
项目需要将网络摄像头接入到服务器上,用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,可以根据具体情况修改。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  OpenCV 网络摄像头