• 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("");
while (cap.isOpened())
    cap >> frame;
    if (frame.empty()) break;

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

Any help greatly appreciated!

  • 2
2 Solutions
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

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