#coding=utf-8
import cv2
import time
if __name__ == '__main__':
cv2.namedWindow("camera",1)
#開啓ip攝像頭
video="http://192.168.31.49:8080/video"
capture =cv2.VideoCapture(video)
num = 0
while True:
success,img = capture.read()
cv2.imshow("camera",img)
#按鍵處理,注意,焦點應當在攝像頭窗口,不是在終端命令行窗口
key = cv2.waitKey(10)
if key == 27:
#esc鍵退出
print("esc break...")
break
if key == ord(' '):
#保存一張圖像
num = num+1
filename = "frames_%s.jpg" % num
cv2.imwrite(filename,img)
capture.release()
cv2.destroyWindow("camera")
注意紅色字體處,
這裏是IP攝像頭的服務地址列表:ide