python调用ip摄像头_在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()

How do I do the same exact thing but with the IP Camera?

My system:

Python 2.7.14

OpenCV 2.4.9

Teledyne Dalsa Genie Nano XL Camera

Help will be highly appreciated

解决方案

I answer my own question reporting what therefore seems to be the most comprehensive overall procedure to Access IP Camera in Python OpenCV.

Given an IP camera:

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:

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()

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值