在OpenCV使用cv2.VideoCapture(RTSP_URL) API函數(shù)對(duì)視頻流解碼時(shí),默認(rèn)解碼硬件是CPU
import cv2
# TP-LINK全系列攝像機(jī)均支持通過RTSP協(xié)議來獲取視頻流覆山,取流地址格式如下
# 主碼流為:rtsp://username:password@ip:port/stream1
# 子碼流為:rtsp://username:password@ip:port/stream2
# port:RTSP端口,默認(rèn)為554,若為默認(rèn)可不填
RTSP_URL = "rtsp://admin:ipc43kp4@192.168.3.51/stream1"
# 默認(rèn)解碼硬件是CPU
cap = cv2.VideoCapture(RTSP_URL)
if not cap.isOpened():
print('Cannot open RTSP stream')
exit(-1)
while True:
_, frame = cap.read()
cv2.imshow('RTSP stream', frame)
if cv2.waitKey(1) == 27:
break
cap.release()
cv2.destroyAllWindows()
要啟動(dòng)GPU Decode模塊,可以輸入?yún)?shù):
cap = cv2.VideoCapture(RTSP_URL, cv2.CAP_FFMPEG, [cv2.CAP_PROP_HW_ACCELERATION, cv2.VIDEO_ACCELERATION_ANY])
import cv2
# TP-LINK全系列攝像機(jī)均支持通過RTSP協(xié)議來獲取視頻流阴绢,取流地址格式如下
# 主碼流為:rtsp://username:password@ip:port/stream1
# 子碼流為:rtsp://username:password@ip:port/stream2
# port:RTSP端口店乐,默認(rèn)為554,若為默認(rèn)可不填
RTSP_URL = "rtsp://admin:ipc43kp4@192.168.3.51/stream1"
# GPU解碼
cap = cv2.VideoCapture(RTSP_URL, cv2.CAP_FFMPEG, [cv2.CAP_PROP_HW_ACCELERATION, cv2.VIDEO_ACCELERATION_ANY])
if not cap.isOpened():
print('Cannot open RTSP stream')
exit(-1)
while True:
_, frame = cap.read()
cv2.imshow('RTSP stream', frame)
if cv2.waitKey(1) == 27:
break
cap.release()
cv2.destroyAllWindows()