我有一个正在进行的项目,通过opencv VideoCapture访问多个IP摄像头,并为其中大多数摄像头工作。
我有一个新的大华PTZ相机,它使用摘要身份验证,而VideoCapture在OpenCV中无法打开它。通过WireShark,我可以看到相机正在返回401Unaothorated。
我在OpenCV文档中没有发现有关auth问题的任何内容。
也许我需要用一些不是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);
}
}这是摄像机的反应:

发布于 2017-09-21 18:48:37
我用相机的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);
}由于某些原因,opencv可以在使用rtsp时执行摘要身份验证。
https://stackoverflow.com/questions/46344625
复制相似问题