BodyBalanceEvaluation/test_dynamic_video.py
2025-07-30 13:47:47 +08:00

71 lines
2.0 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试动态视频生成脚本
用于验证RTSP帧是否真的在变化
"""
import cv2
import numpy as np
import time
from datetime import datetime
def create_test_video_source():
"""
创建一个测试视频源,生成动态变化的图像
"""
# 创建一个640x480的黑色背景
width, height = 640, 480
frame_count = 0
while True:
# 创建黑色背景
frame = np.zeros((height, width, 3), dtype=np.uint8)
# 添加动态元素
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
# 添加时间戳
cv2.putText(frame, timestamp, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
# 添加帧计数
cv2.putText(frame, f'Frame: {frame_count}', (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
# 添加移动的圆形
center_x = int(320 + 200 * np.sin(frame_count * 0.1))
center_y = int(240 + 100 * np.cos(frame_count * 0.1))
cv2.circle(frame, (center_x, center_y), 30, (255, 0, 0), -1)
# 添加变化的矩形
rect_size = int(50 + 30 * np.sin(frame_count * 0.05))
cv2.rectangle(frame, (500, 200), (500 + rect_size, 200 + rect_size), (0, 0, 255), -1)
# 添加随机噪点
noise = np.random.randint(0, 50, (height, width, 3), dtype=np.uint8)
frame = cv2.add(frame, noise)
frame_count += 1
yield frame
time.sleep(1/30) # 30 FPS
def test_rtsp_replacement():
"""
测试用动态视频源替换RTSP
"""
print("开始生成测试视频源...")
print("'q' 键退出")
video_source = create_test_video_source()
for frame in video_source:
cv2.imshow('Test Video Source', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
if __name__ == '__main__':
test_rtsp_replacement()