Files
zjsh_yolov11/camera/siyi_rtsp.py

32 lines
814 B
Python
Raw Normal View History

2025-10-21 14:11:52 +08:00
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)