1

I have been trying to locally (connected with ethernet cable) open an Axis Camera M1054 using OpenCv under Python. I'm working under Windows 7 - 64. I have been using this code with the Axis Camera as the only camera connected :

import sys
import cv2
import numpy as np


capture = cv2.VideoCapture(0)

if not capture.isOpened():
    print "Error opening capture device"
    capture.release()
    cv2.destroyAllWindows()

if capture.isOpened():
    print "Device captured correctly",capture

while 1:

 ret, frame = capture.read()
 print "frame1 =",frame

 if ret == False :
  print "frame is None"
  break

 cv2.imshow('Camera 1',frame)

 if cv2.waitKey(100) == 0x1b:
  print 'ESC pressed. Exiting ...'
  break

capture.release()
cv2.destroyAllWindows()

All I get from it is a black screen and all the matrixes displayed thanks to

print "frame1 =",frame

are full of 0.

I've also tried to call the camera using

cv2.VideoCapture(http://169.254.167.2/axis-cgi/mjpg/video.cgi?resolution=352x240?.mjpg)

But I'm still getting the same result.

It's also important to notice that even if it only display black image and null matrixes, the computer asks me for the camera credentials when I run the code.

I've been looking for a solution but nothing seems to work (I've also tried to get the live video with Windows Media Encoder before and then to call it with

cv2.VideoCapture(0)

But didn't get any better result. Has someone already faced this problem ?

2 Answers 2

4

Reading AXIS documentation here.

I find that you can use RTPS:

cv2.VideoCapture('rtsp://username:[email protected]/axis-media/media.amp')

or using HTTP:

cv2.VideoCapture('http://[email protected]/axis-media/media.amp')

Before trying this solution in your code, I recommend that you (as Adrien mentioned) make sure the link is working in VLC. You can do this by:

  1. Open VLC
  2. Right-click in VLC
  3. Open Media > Open Network
  4. Paste link mentioned above.
  5. Press play.
  6. (If required) - Enter credentials for your Camera.
  7. Press play.

Your video stream should now be displayed in VLC.

Sign up to request clarification or add additional context in comments.

1 Comment

This link helped me to generate the correct link to access your camera model: ispyconnect.com/man.aspx?n=Axis#. For example for my camera model Axis P1357 link generated using the above website: "rtsp://<username:password>@<ip addres>/axis-media/media.amp". This link worked with cv::VideoCapture source("rtsp://<username:password>@<ip addres>/axis-media/media.amp");
2

cv2.VideoCapture(0) won't work with ip camera, it is only for webcams.

For the URL version, could you check that the URL is correct with vlc? It may be different for different camera models, and, according to this non official website, it should be http://169.254.167.2/mjpg/video.mjpg

Note that if the camera is password protected, you have to include the username/password in the url: http://user:[email protected]/mjpg/video.mjpg (usually, default user/pass is root/root). This is of course NOT secure, since the camera password is sent unencrypted on the network, but it is probably not a concern in your case.

1 Comment

Hello Adrien, thanks for your answer, I've been trying my URL in VLC and got errors until I tried yours : 169.254.167.2/mjpg/video.mjpg got opened on VLC. Nevertheless, when I changed my Python code to get it open with OpenCV (i.e. opening it with cv2.VideoCapture('URL') it wasn't working either, do you know any other method more apropriate in order to call an http URL stream ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.