Ask Your Question

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("");
    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 \

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

Thanks for your help,

Regards, Mister Mystère

edit retag flag offensive close merge delete


had the same problem on xp, trying to access an ipcam would never leave 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

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; //"");
    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"

    while (1)
        Mat frame;
        Mat contours;

        bool bSuccess =; // read a new frame from video

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

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

Here, replace the ip address ( in"");

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


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


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

Seen: 11,829 times

Last updated: Feb 26 '14