Max_Sk
Max_Sk

Reputation: 11

How to open a M1054 Axis camera with opencv - Python

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 ?

Upvotes: 1

Views: 7641

Answers (2)

Emir Husic
Emir Husic

Reputation: 747

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.

Upvotes: 4

Adrien Descamps
Adrien Descamps

Reputation: 690

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.

Upvotes: 2

Related Questions