我一直在尝试在本地(使用以太网电缆连接)在Python下使用OpenCv打开Axis Camera M1054。我在Windows 7 - 64下工作。我一直在使用此代码与Axis Camera作为唯一连接的相机:
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()
我从中得到的是一个黑屏,所有矩阵都显示在
print "frame1 =",frame
满是0。
我还尝试使用
调用相机cv2.VideoCapture(http://169.254.167.2/axis-cgi/mjpg/video.cgi?resolution=352x240?.mjpg)
但我仍然得到相同的结果。
同样重要的是要注意即使它只显示黑色图像和空矩阵,当我运行代码时,计算机会要求我提供相机凭据。
我一直在寻找解决方案,但似乎没有任何效果(我之前也尝试使用Windows Media Encoder获取实时视频,然后用
调用它cv2.VideoCapture(0)
但没有得到任何更好的结果。 有人已经遇到过这个问题吗?
答案 0 :(得分:1)
阅读 AXIS 文档 here.
我发现您可以使用 RTPS :
cv2.VideoCapture('rtsp://username:password@169.254.167.2/axis-media/media.amp')
或使用 HTTP :
cv2.VideoCapture('http://username_password@169.254.167.2/axis-media/media.amp')
在您的代码中尝试此解决方案之前,我建议您(正如Adrien所提到的)确保链接在 VLC 中正常工作。你可以这样做:
您的视频流现在应该显示在VLC中。
答案 1 :(得分:0)
cv2.VideoCapture(0)无法使用ip camera,它只适用于网络摄像头。
对于URL版本,您是否可以使用vlc检查URL是否正确?
对于不同的相机型号可能会有所不同,根据this non official website,它应该是http://169.254.167.2/mjpg/video.mjpg
请注意,如果摄像头受密码保护,则必须在网址中包含用户名/密码:http://user:pass@169.254.167.2/mjpg/video.mjpg
(通常,默认用户/密码为root / root)。这当然不安全,因为相机密码是在网络上未加密发送的,但在您的情况下可能不是一个问题。