ip camera in opencv?

Hi! So I have a foscam FI9821EP ip camera that i am trying to use inside opencv.

this code pops up a window, then closes it instantly. The http link works in firefox, but opencv doesn't like it for some reason.

Mat frame;
namedWindow("video", 1);
VideoCapture cap("");
while (cap.isOpened())
    cap >> frame;
    if (frame.empty()) break;

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

Any help greatly appreciated!

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Looks OK, I can just guess that 'isOpened()' might behave differently when you pass the filename via the ctor. The OpenCV site (http://www.answers.opencv.org/question/133/how-do-i-access-an-ip-camera/) states that you need to compile the library with ffmpeg support and gives this sample:

#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://<username:password>@<ip_address>/video.cgi?.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::imshow("Output Window", image);
        if(cv::waitKey(1) >= 0) break;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chemicalx001Author Commented:
thanks! turns out my ffmpeg wasn't installed properly. Anyone having the same problem, follow these instructions:

chemicalx001Author Commented:
the issue was with ffmpeg, as in the answer, follow my link to get instruction.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Digital Cameras / Camcorders

From novice to tech pro — start learning today.