断开连接不再因无头 OpenCV 抛错 - What: Sensor.disconnect() 里的 cv2.destroyAllWindows() 包上 try/except cv2.error:无头构建(opencv-python-headless)没有 highgui,destroyAllWindows 会抛 "The function is not implemented",此前会让 finally 里 disconnect() 的调用方(测试、采集退出路径)拿到一个与传感器无关的异常。 - Why: 跑 SDK 测试时发现 tests/test_calibration.py::test_sensor_cal_path_v2_applies_to_read_info 与 test_set_calibration_swaps_curve 在本机(cv2 4.14.0 headless)稳定失败,断言本身都过了,报错在 finally 的 disconnect() 第 1098 行;这不是滤波改动引入的,但会一直污染每次验证,且 SDK 明确支持无头/CI 使用(backend="cpu"、external-frame 模式)。 - Verification: 修前该模块 7 failed / 13 passed(含上述两个既有测试),修后 20 passed;SDK 全量 335 passed / 15 skipped(唯一失败为需要 1200 帧而 data/sample/s1_480p.mp4 只有 577 帧的 longrun 测试)。 - Not in this change: 未改 disconnect() 的其他分支;未引入 highgui 依赖探测,只在真正调用失败时忽略。

This commit is contained in:
ykcheungab
2026-09-14 10:44:13 +08:00
parent 7f8e5d0975
commit ae5bf0c208
+7
View File
@@ -1095,7 +1095,14 @@ class Sensor:
# self.cap = None
# if self.verbose:
# print("Sensor disconnected.")
try:
cv2.destroyAllWindows()
except cv2.error:
# A headless OpenCV build (``opencv-python-headless``) has no highgui,
# so there is nothing to close. Failing here would leave the rest of
# the shutdown — and every caller that disconnects in a ``finally`` —
# reporting an error that says nothing about the sensor.
pass
# =========================================================================
# Public API - Configuration & Calibration