6

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 ?

Removed by edit: I had considered FFMPEG to be an issue, but v2.4.3. has built-in FFMPEG support and .avi files work although I don't have any FFMPEG library installed (care to explain?)

Thanks in advance,

Regards, Mister Mystère

Mister Mystère
  • 952
  • 2
  • 16
  • 39
  • The VideoCapture class can either access an actual video capturing device (webcam) or open a video file. I'm afraid this will not work with a constant video stream accessed via the network. – Niko May 08 '13 at 21:13
  • I'm pretty sure it's possible since a lot of people managed to do it (among others, the author of the answer [there](http://stackoverflow.com/questions/15584161/ip-camera-and-opencv))... But not me :/ – Mister Mystère May 08 '13 at 21:26
  • ffmpeg is called here, and it's working nicer on linux, than on win (e.g perfectly working on vmbox ubuntu client, but not on the host/xp system) – berak May 08 '13 at 21:47
  • What do you mean? Using windows is a constraint for me. – Mister Mystère May 08 '13 at 21:52

2 Answers2

6

Solved it by copying opencv_ffmpeg.dll from the build\x86\mingw\bin folder of the sources and pasting it next to built DLLs (bin folder accessible through PATH): I have no idea why, but the opencv_ffmpeg_64.dll had been produced instead.

Mister Mystère
  • 952
  • 2
  • 16
  • 39
  • Mystere: Can you please tell where did you paste it. '(bin folder accessible through path)' I dint get here what you trying to say. – Mayur Jan 21 '14 at 05:54
  • It's the folder where the library has been built, of which the path should also be listed in your 'PATH environment variable' (or in your compiler options). – Mister Mystère Jan 21 '14 at 09:46
  • @MisterMystère On windows where do I paste it? – praxmon Feb 12 '14 at 11:25
  • In the folder where OpenCV has been built, the one which is accessible through your PATH environment variable. – Mister Mystère Feb 12 '14 at 18:18
2

Since you can connect and grab frames from a web camera I think that your library is set up correctly and you should be able to connect to IP cameras. I believe that the issue is with the supplied URL address of the camera.

Try logging into the camera and disable its password protection. Remove login and password fields from the URL, so it'll be something like "http://192.168.1.99:99/videostream.cgi?resolution=32&.mjpg". Also, you can log into the camera and check it's resolution. I noticed you have resolution=32 but I think it should be something like resolution=704x480.

Hope this helps.

Alexey
  • 5,898
  • 9
  • 44
  • 81
  • Thanks for your answer. Unfortunately I tried (even without the res) and it doesn't work. I'd like to insist on the fact that this URL has been tried in my browser without any problem (in particular, 32 is for the Foscam protocol) so I doubt it comes from it, except if OpenCV requires specific URL's. I've edited my question above, maybe it... helps to help? Edit: When I say webcam, it's integrated webcam. I've just successfully opened the default camera with the number 0. – Mister Mystère May 08 '13 at 21:49
  • Is `cap.isOpened()` return 1 or zero? – Alexey May 08 '13 at 21:53
  • Yes, if it works in browser, it should work in OpenCV. Except I had issues when connecting to password protected cameras. That's why I suggested to disable camera's password protection, just to test. – Alexey May 08 '13 at 21:56
  • I'd like to remove passwords but it doesn't allow me, I have to specify at least a user so it's the same "problem". Strangely, without any credentials the browser doesn't bother and displays it correctly, but it does mean that it's not the problem. cap.isOpened() returns 0 apparently, since the while() breaks instantly. – Mister Mystère May 08 '13 at 21:59
  • try to connect to some public network camera, just to test if your system is set up properly. You can find some camera addresses on the Internet. – Alexey May 08 '13 at 22:04
  • -Thanks for the link, I had trouble finding a correct one - No, `VideoCapture cap("http://66.184.211.231/mjpg/video.mjpg");` doesn't work neither... But an .avi file does !? – Mister Mystère May 08 '13 at 22:20
  • Yes, `VideoCapture cap("http://66.184.211.231/mjpg/video.mjpg");` worked for me. You can grab frames from web camera or video file streams (like .avi, or .mp4 files), right? – Alexey May 08 '13 at 22:31
  • `VideoCapture cap(0);` and `VideoCapture cap("vid.avi");` work fine, but nothing based on HTTP. I've noticed I had opencv_ffmpeg243_64.dll whereas my Windows's 32bits, could that come from that? – Mister Mystère May 08 '13 at 22:37
  • OpenCV comes with built-in ffmpeg support. Also, for your basic needs there is no need to compile OpenCV libraries for Windows, you can just install OpenCV using the pre-build libraries http://sourceforge.net/projects/opencvlibrary/files/opencv-win/, the installation is pretty straight forward. – Alexey May 08 '13 at 22:51
  • I had to compile it because I'm using QtCreator and it wouldn't work with the precompiled superpacks. But now the rest works, why this doesn't ? – Mister Mystère May 08 '13 at 22:55
  • I see. Not sure why it doesn't work. Maybe your router is blocking the network traffic to/from your application - this is just a guess. – Alexey May 08 '13 at 22:58
  • Hmm... I have no idea about how to change that if that's the case. Sorry, I might be alright in pure programming, but I don't know much about networks. – Mister Mystère May 08 '13 at 23:07
  • good luck, hope you can figure this out. I can be wrong about the router, it can be something else.. – Alexey May 08 '13 at 23:12
  • 1
    Pfiou, I solved it by looking into what I had noticed earlier: the _64 which was appended to my FFMPEG DLL. See below, I just had to copy the 32bits version. No idea why it did that at first. Anyway, thanks for your help, I really appreciated the reactivity ! – Mister Mystère May 08 '13 at 23:40