• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1879
  • Last Modified:

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.
0
chemicalx001
Asked:
chemicalx001
  • 2
2 Solutions
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now