Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV VideoCapture digest authentication

I have an ongoing project accessing multiple IP cameras through opencv VideoCapture, working for most of them.

I ve got a new Dahua PTZ camera that uses digest authentication, and the VideoCapture in OpenCV can't open it. Through WireShark i could see that the camera is returning a 401 Unaothorized.

I found nothing on OpenCV documentation about auth problems.

Maybe i need to use something else that is not OpenCV to solve this?

Here is a minimum working code (if you have a camera to test).

#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:[email protected]/cgi-bin/snapshot.cgi");
        if(!cap.isOpened()){
            cout << "bug" << endl;
            continue;
        }
        Mat frame;
        cap >> frame;
        imshow("test", frame);
    }
}

And here is the camera response:

HTTP Unaothorized Response

like image 301
Diedre Avatar asked Sep 05 '25 20:09

Diedre


1 Answers

I solved the problem by using the camera's rtsp stream instead of the http image. thank you! (if you have this problem in your ip camera try the rtsp stream, they should have a command in the documentation).

Final working code in my Dahua camera:

#include <iostream>
#include <imgproc.hpp>
#include <opencv.hpp>
#include <highgui.hpp>
using namespace std;
using namespace cv;
int main(){
    VideoCapture cap("rtsp://login:[email protected]/cam/realmonitor?channel=1?subtype=0");
    if(!cap.isOpened()){
        cout << "bug" << endl;
        return 1;
    }

    Mat frame;
    cap >> frame;
    imshow("test", frame);

}

For some reason opencv can perform the digest authentication when using rtsp.

like image 124
Diedre Avatar answered Sep 08 '25 16:09

Diedre