接入 Autocal Finger 视频预览
复用 shared FingerAcquisitionWorker 显示处理后画面,并保存视频与配置路径。通过针对性测试和真实视频验证。
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
"""The Autocal sensor tab drives the shared finger acquisition interface."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
class FakeFingerWorker:
|
||||
def __init__(self, *, on_error):
|
||||
self.on_error = on_error
|
||||
self.is_running = False
|
||||
self.started = None
|
||||
self.stopped = []
|
||||
self.packet = None
|
||||
|
||||
def start(self, video, *, config_ref):
|
||||
self.started = (video, config_ref)
|
||||
self.is_running = True
|
||||
|
||||
def stop(self, *, wait=False):
|
||||
self.stopped.append(wait)
|
||||
self.is_running = False
|
||||
|
||||
def latest(self):
|
||||
return self.packet
|
||||
|
||||
def consume_end_reason(self):
|
||||
return "stopped"
|
||||
|
||||
|
||||
def test_video_controls_use_shared_worker_and_show_processed_frame(
|
||||
qt_app, tmp_dir, monkeypatch
|
||||
):
|
||||
from orisys_autocal.ui import finger_source_panel
|
||||
|
||||
monkeypatch.setattr(
|
||||
finger_source_panel, "FingerAcquisitionWorker", FakeFingerWorker
|
||||
)
|
||||
video = tmp_dir / "input.mp4"
|
||||
config = tmp_dir / "sensor.json"
|
||||
video.write_bytes(b"video")
|
||||
config.write_text("{}", encoding="utf-8")
|
||||
|
||||
panel = finger_source_panel.FingerSourcePanel(str(video), str(config))
|
||||
panel.start_button.click()
|
||||
assert panel.worker.started == (str(video), str(config))
|
||||
assert not panel.start_button.isEnabled()
|
||||
|
||||
panel.worker.packet = SimpleNamespace(
|
||||
session_id=1,
|
||||
frame_id=7,
|
||||
timestamp=123.5,
|
||||
processed_frame=np.full((20, 30, 3), (10, 20, 30), dtype=np.uint8),
|
||||
)
|
||||
panel._poll()
|
||||
assert panel._last_image.size().width() == 30
|
||||
assert panel.frame_label.text().find("7") >= 0
|
||||
assert not panel.preview.pixmap().isNull()
|
||||
|
||||
panel.stop_button.click()
|
||||
panel._poll()
|
||||
assert panel.worker.stopped == [False]
|
||||
assert panel.start_button.isEnabled()
|
||||
panel.shutdown()
|
||||
|
||||
|
||||
def test_sensor_tab_is_live_panel_and_paths_are_saved(make_window, tmp_dir):
|
||||
window = make_window()
|
||||
assert window.workspace.page("sensor") is window.finger_source_panel
|
||||
window.finger_source_panel.video_path.setText(str(tmp_dir / "input.mp4"))
|
||||
window.finger_source_panel.config_ref.setText(str(tmp_dir / "sensor.json"))
|
||||
window._persist_prefs()
|
||||
assert window.prefs["finger_video_path"].endswith("input.mp4")
|
||||
assert window.prefs["finger_config_ref"].endswith("sensor.json")
|
||||
|
||||
|
||||
def test_missing_input_is_visible_and_does_not_start_worker(qt_app, monkeypatch):
|
||||
from orisys_autocal.ui import finger_source_panel
|
||||
|
||||
monkeypatch.setattr(
|
||||
finger_source_panel, "FingerAcquisitionWorker", FakeFingerWorker
|
||||
)
|
||||
panel = finger_source_panel.FingerSourcePanel()
|
||||
panel.start_button.click()
|
||||
assert panel.worker.started is None
|
||||
assert panel.start_button.isEnabled()
|
||||
assert panel._error
|
||||
assert panel._error in panel.status_label.text()
|
||||
panel.shutdown()
|
||||
Reference in New Issue
Block a user