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