【发布时间】:2018-05-09 06:52:03
【问题描述】:
我正在尝试使用 openCV 代码从 c++ 访问网络摄像头流,但它失败并显示无法打开流的错误。下面提到的代码在将 URL 替换为 0 时访问网络摄像头。 可从 VLC 和 python 代码访问相同的相机。
#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
int main(int, char**) {
VideoCapture cap("rtsp://admin:admin@10.11.18.185:554/cam/realmonitor?channel=1&subtype=0"); // open the video camera using http protocol with the URL specified
while (!cap.isOpened()) // if not success, exit program
{
cout << "cap not open" << endl;
continue;
//return -1;
}
Mat frame;
namedWindow("MyVideo", CV_WINDOW_AUTOSIZE);
while (1) {
cap.read(frame);
imshow("MyVideo", frame);
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
exit(0);
}
}
}
【问题讨论】:
-
您是否使用 VLC 通过 RTSP 流式传输您的相机?
-
不,我只是在 VLC 中测试流式 url 是否正常工作。
-
consle 或 sth 中的任何错误消息?
标签: c++ opencv video-streaming rtsp ip-camera