Ask Your Question

How do I access an IP Camera?

asked 2012-07-05 12:28:00 -0600

kevin gravatar image

How do I get the images off of an IP camera that streams motion jpegs (mjpeg)?

edit retag flag offensive close merge delete


OpenCV - 3.2.0

Download: IP Camera [JPEG/MJPEG] DirectShow Filter ""

Download: GraphStudio "" Settings: (image description)

cv::VideoCapture cap;;

"1", because "0" - embeded WebCamera.

From: (

5bi4 gravatar image5bi4 ( 2017-04-04 21:50:15 -0600 )edit

Thanks you, My code is working good on my welcam pc but when connect to cam IP network is too slow. Can you help me? This is my code: source = "rtsp://" cap = cv2.VideoCapture(source)

font = cv2.FONT_HERSHEY_COMPLEX while (cap.isOpened()): ret, img =
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces: cv2.rectangle(img, (x,y), (x+w, y+h), (0,255,0), 2) nbr_predicted, conf = recognizer.predict(gray[y:y+h, x:x+w])
if conf < 70: profile=getProfile(nbr_predicted)
if profile != None: cv2.putText(img, "Name: "+str(profile[1]), (x, y+h+30), font, 0.4, (0, 0, 255), 1);

JamseNguyen gravatar imageJamseNguyen ( 2018-04-17 03:43:05 -0600 )edit

James: I couldn't read the camera feed using RTSP, Can you please let me know, If the Computer's IP and CCTV IP Cam's IP needed to be similar(Meaning: In the same network)?? pls let me know

Guru VM gravatar imageGuru VM ( 2018-05-10 01:44:27 -0600 )edit

6 answers

Sort by ยป oldest newest most voted

answered 2012-07-05 12:32:23 -0600

kevin gravatar image

You need to compile OpenCV with ffmpeg support. This works on OSX Lion with a D-Link camera.

#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(! {
        std::cout << "Error opening video stream or file" << std::endl;
        return -1;

    for(;;) {
        if(! {
            std::cout << "No frame" << std::endl;
        cv::imshow("Output Window", image);
        if(cv::waitKey(1) >= 0) break;
edit flag offensive delete link more


I'm currently using opencv 2.4.3 version (in windows 7) because, from what I have read, this version already use the ffmpeg suport, needed to read images and video from ip cameras. However, I still not succeed how to get images from ip cameras. For example, I'm trying to use this code to read an image directly from an Axis camera (I put the ip adress on a web browser and I get an image from the camera):

import cv2

imagePath = "" img = cv2.imread(imagePath) if (img != None): cv2.namedWindow('IP Image',1) cv2.imshow('IP Image',img) cv2.waitKey(0) cv2.destroyWindow('IP Image')

Does anyone know what I'm missing?

pmj gravatar imagepmj ( 2012-11-30 06:51:08 -0600 )edit

pmj, I don't think imread() supports URLs. FFmpeg supports URLs through video interface only.

jukkaho gravatar imagejukkaho ( 2013-01-30 08:38:04 -0600 )edit
Rui Marques gravatar imageRui Marques ( 2013-03-07 13:40:47 -0600 )edit

answered 2014-02-26 09:02:18 -0600

Ashish Ranjan gravatar image

You can use the following opencv c++ code for windows to get videostream from your IP WEBCAM app on android phone.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
    VideoCapture cap; //"");
    if (!cap.isOpened())  // if not success, exit program
        cout << "Cannot open the video cam" << endl;
        return -1;

   double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
   double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

    cout << "Frame size : " << dWidth << " x " << dHeight << endl;

    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

    while (1)
        Mat frame;
        Mat contours;

        bool bSuccess =; // read a new frame from video

         if (!bSuccess) //if not success, break loop
             cout << "Cannot read a frame from video stream" << endl;

        flip(frame, frame, 1);
        imshow("MyVideo", frame); //show the frame in "MyVideo" window

        Canny(frame, contours, 500, 1000, 5, true);
        imshow("MyNegativeVideo", contours);

        if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
            cout << "esc key is pressed by user" << endl;
    return 0;

Here, replace the ip address ( in"");

with your ip address !! But make sure you have, ?x.mjpeg ,in the end (where x can be any string).

If this doesn't work then you should find out what your full ip address is? i.e. find out what is the string after the ip (In my case it was "/video" as shown in above address)

edit flag offensive delete link more


Folks, I am using rtsp to access video stream from IP Camera to OpenCV(in a server), please find the code

from imutils import contours import numpy as np import argparse import imutils import cv2 camera = cv2.VideoCapture("rtsp://admin:[email protected]:554/Streaming/Channels/102/") while(camera.isOpened()): ret, frame = if ret: gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray = cv2.bilateralFilter(gray, 11, 17, 17) edged = cv2.Canny(gray, 30, 200) blur = cv2.Laplacian(gray, cv2.CV_64F).var() if blur < 100: print "blurred vision" cv2.imshow("Blur", gray)

      if cv2.waitKey(10) & 0xFF == ord('q'):

But camera is not opened, Can you please help me fix this problem? OS: Ubuntu 16.04

Guru VM gravatar imageGuru VM ( 2018-05-10 01:37:24 -0600 )edit

answered 2016-08-19 07:30:11 -0600

I'm new in this forum so first of all: Hi everyone and thanks in advance for your help.

I'm currently developing a c++ project (Xcode project over mac osx) with opencv to process an "axis v59" ip camera. I have problems to connect my aplicattion with the camera. This is the code I'm using:

cv::VideoCapture camera;""); if (camera.isOpened()==true) { cv::namedWindow("camera"); int key = 0; while (key != 27) { cv::Mat_<cv::vec3b> image; camera.grab(); camera.retrieve(image); cv::imshow("camera",image); key = cv::waitKey(10);

    printf("No se puede leer la senal");

When I execute the code I obtain this: "WARNING: Couldn't read movie file

The camera is configurated to not need user and password for viewer login. I have tried to recibe that url from VLC and from my browser and it works perfectly.

Do you have any idea of wha I'm doing wrong??


edit flag offensive delete link more

answered 2015-09-14 14:40:25 -0600

zenit_543 gravatar image

this method worked like a charm for me!!! tnx Ashish Ranjan!

edit flag offensive delete link more

answered 2013-01-28 05:13:34 -0600

This works for me under Windows7 + OpenCV 2.4.3

edit flag offensive delete link more

answered 2013-03-04 01:06:53 -0600

Diep gravatar image

How to build OpenCV-2.4.3 with ffmpeg? I can't do it!

edit flag offensive delete link more


replace the ip address ( in"");

skyme gravatar imageskyme ( 2016-09-09 03:41:35 -0600 )edit

Question Tools



Asked: 2012-07-05 12:28:00 -0600

Seen: 125,019 times

Last updated: Aug 19 '16