| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import sys
- import os
- sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
- import numpy as np
- import pytest
- from polling_tracker import PollingTrackingCoordinator, CaptureRecord
- from tracker import TrackedPerson
- class FakePanorama:
- def __init__(self):
- self.frame = np.zeros((480, 640, 3), dtype=np.uint8)
- def get_frame(self):
- return self.frame.copy()
- class FakePTZ:
- def __init__(self):
- self.commands = []
- self.current_position = type("P", (), {"pan": 0, "tilt": 0, "zoom": 1})()
- def goto_exact_position(self, pan, tilt, zoom):
- self.commands.append((pan, tilt, zoom))
- return True
- def get_current_position(self):
- return self.current_position
- def calculate_ptz_position(self, x, y, zoom=None):
- return x * 180, y * 90, zoom or 8
- class FakeTracker:
- def __init__(self, persons):
- self.persons = persons
- def update(self, frame):
- return self.persons
- def test_update_active_targets():
- pan = FakePanorama()
- ptz = FakePTZ()
- tracker = FakeTracker([
- TrackedPerson(track_id=1, bbox=(10, 20, 30, 40), center=(20, 30), confidence=0.9),
- TrackedPerson(track_id=2, bbox=(50, 60, 70, 80), center=(60, 70), confidence=0.8),
- ])
- coord = PollingTrackingCoordinator(pan, ptz, tracker, config={"max_tracking_targets": 4})
- frame = pan.get_frame()
- coord._update_active_targets(tracker.update(frame), frame.shape)
- assert len(coord.active_targets) == 2
- assert 1 in coord.target_order
- assert 2 in coord.target_order
- def test_advance_loop():
- coord = PollingTrackingCoordinator.__new__(PollingTrackingCoordinator)
- coord.target_order = [1, 2, 3]
- coord.current_index = 0
- coord._advance()
- assert coord.current_index == 1
- coord.current_index = 2
- coord._advance()
- assert coord.current_index == 0
- def test_capture_record_creation():
- record = CaptureRecord(
- track_id=1,
- timestamp=1.0,
- position=(0.5, 0.5),
- ptz_position=(90.0, 45.0, 8),
- ptz_image=np.zeros((100, 100, 3), dtype=np.uint8),
- panorama_image=None,
- confidence=0.9,
- )
- assert record.track_id == 1
|