#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摄像头的服务地址列表:
- http://192.168.31.49:8080/video 是 MJPEG URL.
- http://192.168.31.49:8080/shot.jpg 获取最新一帧
- http://192.168.31.49:8080/audio.wav 是WAV格式的音频流
- http://192.168.31.49:8080/audio.aac 是AAC格式的音频流(如果硬件支持的话)
- http://192.168.31.49:8080/audio.opus 是Opus格式的音频流
- http://192.168.31.49:8080/focus 对焦摄像头
- http://192.168.31.49:8080/nofocus 释放对焦