我有一个正在进行的项目,通过opencv VideoCapture访问多个IP摄像机,为其中大多数摄像机工作。
我有一个新的大华PTZ相机,使用摘要认证,而OpenCV中的视频捕获无法打开它。通过WireShark,我可以看到摄像机返回的是一个401未经麻醉的图像。
我在OpenCV文档中没有发现任何关于身份验证问题的信息。
也许我需要使用其他不是OpenCV的东西来解决这个问题?
#include <iostream> #include <imgproc.hpp> #include <opencv.hpp> #include <highgui.hpp> using namespace std; using namespace cv; int main(){ while(1){ VideoCapture cap("http://login:password@111.111.111.111/cgi-bin/snapshot.cgi"); if(!cap.isOpened()){ cout << "bug" << endl; continue; } Mat frame; cap >> frame; imshow("test", frame); } }
我通过使用相机的rtsp流而不是http图像解决了这个问题。非常感谢。(如果您的ip摄像机中存在此问题,请尝试rtsp流,文档中应该有一个命令)。
我的大华相机的最终工作代码:
#include <iostream> #include <imgproc.hpp> #include <opencv.hpp> #include <highgui.hpp> using namespace std; using namespace cv; int main(){ VideoCapture cap("rtsp://login:password@111.111.111.111/cam/realmonitor?channel=1?subtype=0"); if(!cap.isOpened()){ cout << "bug" << endl; return 1; } Mat frame; cap >> frame; imshow("test", frame); }