IP Camera access using OpenCV

前端 未结 3 1609
失恋的感觉
失恋的感觉 2020-12-14 12:54

The code given below is for accessing an Axis IP camera using OpenCV. On running the program it first displays \"Error in opening cap_ffmpeg_impl...\" and then it displays <

相关标签:
3条回答
  • 2020-12-14 13:14

    I faced similar problem when trying to display IP camera using the public IP camera. Opencv needs some typical kind of URL to open the camera.Try the URL from below code. Heres the code that worked for me.

    int main(int, char**) {
        cv::VideoCapture vcap;
        cv::Mat image;
    
        // This works on a D-Link CDS-932L
        const std::string videoStreamAddress = "http://ID:PASSWORD@IPADDRESS:PORTNO/mjpeg.cgi?user=ID&password=ID:PASSWORD&channel=0&.mjpg";
           //open the video stream and make sure it's opened
        if(!vcap.open(videoStreamAddress)) {
            std::cout << "Error opening video stream or file" << std::endl;
            return -1;
        }
    
        for(;;) {
            if(!vcap.read(image)) {
                std::cout << "No frame" << std::endl;
                cv::waitKey();
            }
            cv::imshow("Output Window", image);
    
            if(cv::waitKey(1) >= 0) break;
        }   
    
    }
    

    Copy this code as it is and try.

    #include <stdio.h>
    #include <opencv2/opencv.hpp>
    #include <iostream>
    int main(int, char**) {
        cv::VideoCapture vcap;
        cv::Mat image;
    
        // This works on a D-Link CDS-932L
    
        const std::string videoStreamAddress = "http://USER:PWD@IPADDRESS:8088/mjpeg.cgi?user=USERNAME&password=PWD&channel=0&.mjpg";
           //open the video stream and make sure it's opened
        if(!vcap.open(videoStreamAddress)) {
            std::cout << "Error opening video stream or file" << std::endl;
            return -1;
        }
    
        for(;;) {
            if(!vcap.read(image)) {
                std::cout << "No frame" << std::endl;
                cv::waitKey();
            }
            cv::imshow("Output Window", image);
    
            if(cv::waitKey(1) >= 0) break;
        }   
    
    }
    
    0 讨论(0)
  • 2020-12-14 13:16

    I installed "Mini WebCam" app on my iphone and used it as an ip camera with "http://192.168.1.103" as it's address. In addition I used this piece of code:

    VideoCapture capture;
    Mat image;
    if (!capture.open("http://192.168.1.103/video.cgi?.mjpg")) {
        cout << "Error opening video stream or file" << endl;
        return -1;
    }
    ....
    

    it works.(http://192.168.1.103/video.cgi?.mjpg)

    0 讨论(0)
  • 2020-12-14 13:18

    The following works for an Axis M1004-W connected to my computer via ethernet cable:

    1. In the browser of your choice (I'm using Chrome), navigate to the camera's IP address. Provide credentials as necessary.
    2. You should be looking at a live stream from your camera. Right-click on the video stream and select "Inspect Element" (or its equivalent in non-Chrome browsers).
    3. You should see a variable called src - this is what you can use within OpenCV to access the camera directly. Mine is /mjpg/video.mjpg, and I bet yours will be similar.

    The address you give to OpenCV should look like this:

    http://<USERNAME>:<PASSWORD>@<IP_ADDRESS>/<the value of src>
    

    This is what mine looks like:

    http://uname:login@192.168.0.0/mjpg/video.mjpg
    

    I entered my address into your code and can see the video stream from an OpenCV window.

    0 讨论(0)
提交回复
热议问题