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("http://192.168.1.90:88/cgi-bin/CGIStream.cgi?cmd=GetMJStream&usr=xxx&pwd=xxx&.mjpg");
while (cap.isOpened())
{
    cap >> frame;
    if (frame.empty()) break;

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


Any help greatly appreciated!

thanks.
chemicalx001Asked:
Who is Participating?

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

x
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.

jkrCommented:
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::waitKey();
        }
        cv::imshow("Output Window", image);
        if(cv::waitKey(1) >= 0) break;
    }   
}

Open in new window

0

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:

http://stackoverflow.com/questions/7075180/how-to-compile-opencv-2-3-with-ffmpeg-support-with-visual-studio-2010
0
chemicalx001Author Commented:
the issue was with ffmpeg, as in the answer, follow my link to get instruction.
0
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.