""" 讀取視頻流(相機,視頻,ip相機) """ import cv2 # url = "rtsp://admin:admin@ip:port/live" # ip相機 admin:admin 是賬號和密碼 # cap = cv2.VideoCapture("./video/01.mp4") # 視頻 cap = cv2.VideoCapture(0) # 0自帶相機,1外接相機 # 循環讀取每一幀 while(cap.isOpened()): ret, frame = cap.read() # True (480, 640, 3) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # 灰度圖 # cv2.namedWindow("resized", 0) # 0可以改變窗口大小了 # cv2.resizeWindow("resized", 640, 480) cv2.imshow("frame", gray) # 顯示圖片 if cv2.waitKey(1) & 0xFF == ord("q"): # 按q退出 break # 釋放並關閉所有窗口 cap.release() cv2.destroyAllWindows()