How do I access an IP Camera?
How do I get the images off of an IP camera that streams motion jpegs (mjpeg)?
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;
}
}
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?
If this doesn't work for you, check this solution: http://answers.opencv.org/question/3664/ip-camera-access/?answer=8716#post-id-8716
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)
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 = 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
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!!
this method worked like a charm for me!!! tnx Ashish Ranjan!
This works for me under Windows7 + OpenCV 2.4.3
How to build OpenCV-2.4.3 with ffmpeg? I can't do it!
replace the ip address (192.168.226.101:8080) in scotland.gov.uk cap.open("http://192.168.226.101:8080/video?x.mjpeg");
Asked: 2012-07-05 12:28:00 -0600
Seen: 125,566 times
Last updated: Aug 19 '16
How do you set up/access a wireless ip camera with OpenCV?
Need to read video in MJPEG format using VideoCapture
How does VideoCapture from USB Webcam on Windows using DirectShow and MJPG work?
How to read MJPEG frames from USB camera
How to Get MJPEG compression format from webcam!
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)
"1", because "0" - embeded WebCamera.
From: http://roboforum.ru/forum51/topic11560.html (http://roboforum.ru/forum51/topic1156...)
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);
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