First time here? Check out the FAQ!

Ask Your Question
5

How do I access an IP Camera?

asked Jul 5 '12

kevin gravatar image

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

Preview: (hide)

Comments

OpenCV - 3.2.0

Download: IP Camera [JPEG/MJPEG] DirectShow Filter "http://www.webcamxp.com/download.aspx"

Download: GraphStudio "http://blog.monogram.sk/janos/tools/monogram-graphstudio/" Settings: http://roboforum.ru/download/file.php?id=23987&mode=view&sid=13b1d266b8bb6a454544a7a3ca722d3f (image description)

cv::VideoCapture cap; 
cap.open(1);

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

From: http://roboforum.ru/forum51/topic11560.html (http://roboforum.ru/forum51/topic1156...)

5bi4 gravatar image5bi4 (Apr 5 '17)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://10.1.21.16:554/profile1" cap = cv2.VideoCapture(source)

font = cv2.FONT_HERSHEY_COMPLEX while (cap.isOpened()): ret, img = cap.read()
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 (Apr 17 '18)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 (May 10 '18)edit

6 answers

Sort by » oldest newest most voted
12

answered Jul 5 '12

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(!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;
    }   
}
Preview: (hide)

Comments

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 = "http://10.64.13.14/axis-cgi/jpg/image.cgi?resolution=320x240" 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 (Nov 30 '12)edit

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

jukkaho gravatar imagejukkaho (Jan 30 '13)edit
6

answered Feb 26 '14

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; //

    cap.open("http://192.168.226.101:8080/video?x.mjpeg");
    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"
    namedWindow("MyNegativeVideo",CV_WINDOW_AUTOSIZE);

    while (1)
    {
        Mat frame;
        Mat contours;

        bool bSuccess = cap.read(frame); // read a new frame from video

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

        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;
            break;
       }
    }
    return 0;
}

Here, replace the ip address (192.168.226.101:8080) in

cap.open("http://192.168.226.101:8080/video?x.mjpeg");

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)

Preview: (hide)

Comments

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:123456@192.168.1.13:554/Streaming/Channels/102/") while(camera.isOpened()): ret, frame = camera.read() 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'):
        break

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

Guru VM gravatar imageGuru VM (May 10 '18)edit
0

answered Aug 19 '16

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; camera.open("http://192.168.0.90/axis-cgi/mjpg/video.cgi"); 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);

    }
}
else{
    printf("No se puede leer la senal");
}

When I execute the code I obtain this: "WARNING: Couldn't read movie file http://192.168.0.90/axis-cgi/mjpg/vid...

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

Thanks!!

Preview: (hide)
0

answered Sep 14 '15

zenit_543 gravatar image

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

Preview: (hide)
0

answered Jan 28 '13

This works for me under Windows7 + OpenCV 2.4.3

Preview: (hide)
-2

answered Mar 4 '13

Diep gravatar image

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

Preview: (hide)

Comments

replace the ip address (192.168.226.101:8080) in scotland.gov.uk cap.open("http://192.168.226.101:8080/video?x.mjpeg");

skyme gravatar imageskyme (Sep 9 '16)edit

Question Tools

3 followers

Stats

Asked: Jul 5 '12

Seen: 126,075 times

Last updated: Aug 19 '16