bushu
This commit is contained in:
32
camera/siyi_rtsp.py
Normal file
32
camera/siyi_rtsp.py
Normal file
@ -0,0 +1,32 @@
|
||||
import cv2
|
||||
|
||||
def read_rtsp(rtsp_url):
|
||||
# 创建 VideoCapture 对象
|
||||
cap = cv2.VideoCapture(rtsp_url)
|
||||
# 判断是否成功连接到 RTSP 流
|
||||
if not cap.isOpened():
|
||||
print("无法连接到 RTSP 流")
|
||||
return
|
||||
|
||||
try:
|
||||
while True:
|
||||
# 读取一帧
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
print("无法读取帧")
|
||||
break
|
||||
|
||||
# 显示帧
|
||||
cv2.imshow('frame', frame)
|
||||
|
||||
# 按下 'q' 键退出
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
finally:
|
||||
# 释放资源
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
if __name__ == '__main__':
|
||||
rtsp_url = "rtsp://192.168.144.25:8554/main.264" # 替换为实际的 RTSP 地址
|
||||
read_rtsp(rtsp_url)
|
||||
Reference in New Issue
Block a user