在Python OpenCV中访问IP摄像机 [英] Access IP Camera in Python OpenCV
问题描述
如何访问我的IP摄像机流?
How do I access my IP Camera stream?
用于显示标准网络摄像头流的代码是
Code for displaying a standard webcam stream is
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
除了IP摄像机外,我该如何做同样的事情?
How do I do the same exact thing but with the IP Camera?
我的系统:
- Python 2.7.14
- OpenCV 2.4.9
- Teledyne Dalsa Genie Nano XL相机
我们将非常感谢您的帮助
Help will be highly appreciated
推荐答案
我回答了我自己的问题,报告了什么似乎是在Python OpenCV中访问IP摄像机的最全面的总体过程.
I answer my own question reporting what therefore seems to be the most comprehensive overall procedure to Access IP Camera in Python OpenCV.
提供IP摄像机:
- 找到您的相机
IP
地址 - 找到访问IP地址的
port
- 找到相机提供商指定的
protocol
(HTTP/RTSP等)
- Find your camera
IP
address - Find the
port
where the IP address is accessed - Find the
protocol
(HTTP/RTSP etc.) specified by the camera provider
然后,如果您的相机受到保护,请继续查找:
Then, if your camera is protected go ahead and find out:
- 您的
username
- 您的
password
- your
username
- your
password
然后使用您的数据运行以下脚本:
Then use your data to run the following script:
"""Access IP Camera in Python OpenCV"""
import cv2
stream = cv2.VideoCapture('protocol://IP:port/1')
# Use the next line if your camera has a username and password
# stream = cv2.VideoCapture('protocol://username:password@IP:port/1')
while True:
r, f = stream.read()
cv2.imshow('IP Camera stream',f)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
注意:在我最初的问题中,我指定要与 Teledyne Dalsa Genie Nano XL相机一起使用.不幸的是,对于这种摄像机,这种访问IP摄像机视频流的常规方法不起作用,必须使用 Sapera SDK 才能从设备中抓取帧.
NOTE: In my original question I specify to being working with Teledyne Dalsa Genie Nano XL Camera. Unfortunately for this kind of cameras this normal way of accessing the IP Camera video stream does not work and the Sapera SDK must be employed in order to grab frames from the device.
这篇关于在Python OpenCV中访问IP摄像机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!