dongchang/tests/test_camera.py
2025-01-13 11:25:23 +08:00

22 lines
661 B
Python

import cv2
import numpy as np
import time
from src.camera_handler import RTSPCamera
def test_rtsp_camera():
# 使用本地测试视频或摄像头
camera = RTSPCamera(0) # 使用本地摄像头进行测试
print("测试摄像头启动...")
camera.start()
time.sleep(2) # 等待摄像头初始化
print("测试获取帧...")
frame = camera.get_frame()
assert frame is not None, "无法获取视频帧"
assert isinstance(frame, np.ndarray), "帧格式不正确"
assert len(frame.shape) == 3, "帧维度不正确"
print("测试摄像头停止...")
camera.stop()
print("摄像头测试完成!")