Files
autopilot/old/test_visualization_only.py

67 lines
3.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
Упрощенный тест для проверки системы визуализации без браузера
"""
import numpy as np
from PIL import Image
import cv2
from autopilot import AutoPilot
from visualization import VisualizationManager, SimMode
def test_visualization_only():
"""Тестирует только систему визуализации без симулятора"""
print("Тест системы визуализации...")
# Создаем менеджер визуализации
viz_manager = VisualizationManager("Test - Visualization Only")
# Создаем автопилот с менеджером визуализации
autonome_pilot = AutoPilot(initial_x=0.0, initial_y=0.0, viz_manager=viz_manager)
# Создаем тестовые изображения
width, height = 640, 480
test_image1 = np.zeros((height, width, 3), dtype=np.uint8)
test_image2 = np.zeros((height, width, 3), dtype=np.uint8)
# Добавляем объекты для отслеживания
cv2.circle(test_image1, (width//2, height//2), 50, (255, 255, 255), -1)
cv2.circle(test_image1, (100, 100), 20, (255, 0, 0), -1)
cv2.circle(test_image1, (width-100, height-100), 20, (0, 255, 0), -1)
cv2.circle(test_image2, (width//2 + 10, height//2 + 5), 50, (255, 255, 255), -1)
cv2.circle(test_image2, (110, 105), 20, (255, 0, 0), -1)
cv2.circle(test_image2, (width-90, height-95), 20, (0, 255, 0), -1)
# Конвертируем в PIL Image
pil_image1 = Image.fromarray(test_image1)
pil_image2 = Image.fromarray(test_image2)
print("Обрабатываем первое изображение...")
autonome_pilot.handle(pil_image1)
print("Обрабатываем второе изображение...")
autonome_pilot.handle(pil_image2)
# Симулируем движение дрона
print("Симулируем движение дрона...")
for i in range(10):
# Обновляем глобальную карту
viz_manager.update_global_map(i * 10, i * 5, SimMode.OPERATOR if i < 5 else SimMode.AUTONOME)
viz_manager.update_display()
# Получаем состояние дрона
drone_state = autonome_pilot.get_drone_state()
print(f"Позиция дрона: ({drone_state['x']:.2f}, {drone_state['y']:.2f})")
print(f"Угол дрона: {drone_state['angle_degrees']:.1f}°")
print("Тест завершен! Окно визуализации должно показывать:")
print("- Глобальную карту с траекторией (синий - оператор, красный - автономный)")
print("- Детекцию ключевых точек на текущем кадре")
print("- Сопоставление точек между кадрами")
# Показываем финальное состояние
viz_manager.show_final()
if __name__ == "__main__":
test_visualization_only()