python 使用OpenCV2打开本地及网络摄像头&本地及网络视频

'''
python 使用OpenCV2打开本地及网络摄像头&本地及网络视频 by 郑瑞国
'''
import cv2

user, pwd, ip, channel = "admin", "12345", "192.168.1.120", 1

#video_stream_path = 0  # local camera (e.g. the front camera of laptop)
#video_stream_path = r'D:/AI/08_imageAI/ImageAI-master/videos/traffic.mp4'  # the path of video file
video_stream_path = "rtsp://%s:%s@%s/h265/ch%s/main/av_stream" % (user, pwd, ip, channel)  # HIKIVISION old version 2015
#video_stream_path = "rtsp://%s:%s@%s//Streaming/Channels/%d" % (user, pwd, ip, channel)  # HIKIVISION new version 2017
#video_stream_path = "rtsp://%s:%s@%s/cam/realmonitor?channel=%d&subtype=0" % (user, pwd, ip, channel)  # dahua

cap = cv2.VideoCapture(video_stream_path)

while(True):
    ret,frame=cap.read()
    
    cv2.imshow('frame',frame)
    if cv2.waitKey(1)&0xff == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值