Ask Your Question
0

cv::VideoCapture works for webcams but not IP cameras

asked 2013-05-08 16:38:25 -0600

mistermystere gravatar image

updated 2013-05-08 17:25:22 -0600

It had to happen, I'm stuck in the last phase of my project, when I want to use my code which works like a charm on my webcam, on an IP camera. The URL works perfectly in my browser, but nothing comes out with OpenCV... Here is my code:

#include <opencv/highgui.h>

using namespace cv;

int main(int argc, char *argv[])
{
    Mat frame;
    namedWindow("video", 1);
    VideoCapture cap("http://192.168.1.99:99/videostream.cgi?resolution=32&rate=0&user=admin&pwd=password&.mjpg");
    while ( cap.isOpened() )
    {
        cap >> frame;
        if(frame.empty()) break;

        imshow("video", frame);
        if(waitKey(30) >= 0) break;
    }

    return 0;
}

And the compiler settings :

//Added to the .pro file of QtCreator
INCLUDEPATH += C:\\OpenCV243\\release\\include
LIBS += -LC:\\OpenCV243\\release\\lib \
    -lopencv_core243.dll \
    -lopencv_highgui243.dll

I've tested opening a .avi file with the same code and it works... But a public IP camera URL like http://66.184.211.231/mjpg/video.mjpg doesn't ! What's the matter then ?

Thanks for your help,

Regards, Mister Mystère

edit retag flag offensive close merge delete

Comments

had the same problem on xp, trying to access an ipcam would never leave cap.open() it just got stuck there.

it seems to work much better running linux or such

berak gravatar imageberak ( 2013-05-11 04:12:16 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2014-02-26 09:05:57 -0600

Ashish Ranjan gravatar image

You can use the following opencv c++ code for windows to get videostream from your IP WEBCAM app on android phone.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap; //

    cap.open("http://192.168.226.101:8080/video?x.mjpeg");
    if (!cap.isOpened())  // if not success, exit program
    {
        cout << "Cannot open the video cam" << endl;
        return -1;
    }

   double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
   double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

    cout << "Frame size : " << dWidth << " x " << dHeight << endl;

    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
    namedWindow("MyNegativeVideo",CV_WINDOW_AUTOSIZE);

    while (1)
    {
        Mat frame;
        Mat contours;

        bool bSuccess = cap.read(frame); // read a new frame from video

         if (!bSuccess) //if not success, break loop
        {
             cout << "Cannot read a frame from video stream" << endl;
             break;
        }

        flip(frame, frame, 1);
        imshow("MyVideo", frame); //show the frame in "MyVideo" window

        Canny(frame, contours, 500, 1000, 5, true);
        imshow("MyNegativeVideo", contours);

        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;
            break;
       }
    }
    return 0;
}

Here, replace the ip address (192.168.226.101:8080) in

cap.open("http://192.168.226.101:8080/video?x.mjpeg");

with your ip address !! But make sure you have, ?x.mjpeg ,in the end (where x can be any string).

If this doesn't work then you should find out what your full ip address is? i.e. find out what is the string after the ip (In my case it was "/video" as shown in above address)

edit flag offensive delete link more

Comments

Hi, I am using DCS-930L IP Camera and I the IP Camera only can work in web browser but can't work in C++. Do you have any idea?

LCY gravatar imageLCY ( 2018-11-25 00:58:31 -0600 )edit

If image source was flowing in any kind of widget display which displays in browser, you could get element which was contained in widget. OR, you can just insert all web page with all elements into your application then you can get both source and display widget. It means that you have both, and can use one of them as you wish.

Xyre gravatar imageXyre ( 2019-04-17 01:32:32 -0600 )edit

Question Tools

Stats

Asked: 2013-05-08 16:38:25 -0600

Seen: 12,078 times

Last updated: Feb 26 '14