在 Python OpenCV 中访问网络摄像机 [英] Access IP Camera in Python OpenCV

查看:65
本文介绍了在 Python OpenCV 中访问网络摄像机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问我的网络摄像机流?

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 相机

非常感谢您的帮助

您可以将视频捕获对象用作

You can use video capture Object as

camera = cv2.VideoCapture("IP:PORT/video")

推荐答案

我回答了我自己的问题,报告了在 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 摄像头:

Given an IP camera:

  • 找到你的相机IP地址
  • 找到访问IP地址的端口
  • 找到相机提供者指定的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:

  • 您的用户名
  • 您的密码

然后使用您的数据运行以下脚本:

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 中访问网络摄像机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆