added ruff code reivew

This commit is contained in:
ykcheungab
2026-09-27 19:21:55 +08:00
parent 07da372204
commit e2ac36269c
110 changed files with 890 additions and 426 deletions
+11 -7
View File
@@ -1,6 +1,7 @@
import os
import sys
os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0"
import cv2
@@ -9,10 +10,11 @@ _local_src = os.path.join(os.path.dirname(__file__), "src")
if _local_src not in sys.path:
sys.path.insert(0, _local_src)
import orisys
import numpy as np
import time
import argparse
import time
import orisys
def main():
parser = argparse.ArgumentParser()
@@ -30,11 +32,13 @@ def main():
# 方式1: 从视频文件读取
try:
input = int(args.video)
is_camera = True
sensor = orisys.Sensor(input, config_name=args.config, cal_path= args.cal, verbose=args.verbose, debug=args.debug)
except:
is_camera = False
except ValueError:
# Not a camera index: treat the argument as a video-file path. Only the
# conversion is guarded, so a genuine Sensor construction error is not
# swallowed and retried as a file path.
sensor = orisys.Sensor(args.video, config_name=args.config, cal_path= args.cal, verbose=args.verbose, debug=args.debug)
else:
sensor = orisys.Sensor(input, config_name=args.config, cal_path= args.cal, verbose=args.verbose, debug=args.debug)
# sensor = orisys.Sensor(2, config_name="./config/ddjx01_q6a.json", cal_path= "./config/ddjx01.npy", isstitch=True, cuda=False, verbose=True, backend='cpu')
# 方式2: 从摄像头读取(取消注释使用)
+7 -4
View File
@@ -1,12 +1,15 @@
import os
os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0"
import cv2
import orisys
import numpy as np
import time
import cv2
import numpy as np
import pyqtgraph as pg
import orisys
def create_plot():
p1 = win.addPlot(title="法相力")
p1.setLabel('bottom', '时间', units='s')
@@ -149,7 +152,7 @@ def main():
print("\n 停止程序")
break
if key == ord("s"):
save_path = f"./data/pulse_test.mp4"
save_path = "./data/pulse_test.mp4"
# Ensure directory exists
os.makedirs(os.path.dirname(save_path), exist_ok=True)
# Get frame dimensions from the actual frame
+16 -9
View File
@@ -46,7 +46,7 @@ import os
import shlex
import sys
from pathlib import Path
from typing import Optional, Union
from typing import Union
os.environ.setdefault("OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS", "0")
@@ -60,13 +60,14 @@ except ImportError as exc: # pragma: no cover
) from exc
import cv2
from orisys.capture import is_live_camera, list_cameras
from orisys.finger import FingerRuntime
Source = Union[int, str]
def _parse_source(token: str) -> Optional[Source]:
def _parse_source(token: str) -> Source | None:
"""Accept camera index int, numeric string, V4L path, or filesystem path."""
text = str(token).strip().strip('"').strip("'")
if not text:
@@ -116,9 +117,9 @@ class UartFingerController:
self.show = show
self.verbose = verbose
self.runtime: Optional[FingerRuntime] = None
self._connected_source: Optional[Source] = None
self._last_search_source: Optional[Source] = None
self.runtime: FingerRuntime | None = None
self._connected_source: Source | None = None
self._last_search_source: Source | None = None
self._streaming = False
self._should_quit = False
@@ -134,14 +135,18 @@ class UartFingerController:
if self.runtime is not None:
try:
self.runtime.close()
except Exception: # noqa: BLE001
except Exception: # noqa: BLE001, S110 - teardown must not raise
# Best-effort release: a close failure here has no recovery path in
# a shutdown request handler, and raising would skip the reset below.
pass
self.runtime = None
self._connected_source = None
if self.show:
try:
cv2.destroyAllWindows()
except Exception: # noqa: BLE001
except Exception: # noqa: BLE001, S110 - no GUI window to destroy
# Expected when no window was ever created (headless/--no-show run):
# this is a normal no-op, not a hidden failure.
pass
def _resolve_connect_source(self, args: list[str]) -> Source:
@@ -220,7 +225,7 @@ class UartFingerController:
except Exception: # noqa: BLE001
return False
def _poll_command_line(self, *, blocking: bool = True) -> Optional[str]:
def _poll_command_line(self, *, blocking: bool = True) -> str | None:
"""Read one command line if available; return None on timeout/empty."""
if not blocking and self.ser.in_waiting <= 0:
return None
@@ -447,7 +452,9 @@ def main(argv: list[str] | None = None) -> int:
print("\nInterrupted.", flush=True)
try:
controller.reply("OK quit")
except Exception: # noqa: BLE001
except Exception: # noqa: BLE001, S110 - peer may already be gone
# We are already shutting down on Ctrl-C; failing to send the final
# acknowledgement (peer closed the port) must not mask the exit path.
pass
finally:
controller.close_runtime()
+2 -3
View File
@@ -36,10 +36,9 @@ from __future__ import annotations
import argparse
import csv
import statistics
import sys
from collections.abc import Sequence
from pathlib import Path
from typing import Sequence
import numpy as np
@@ -79,7 +78,7 @@ def _window(
valid = _column(rows, VALID_COLUMN)
mask = np.ones(times.shape, dtype=bool)
if times.size:
mask &= times == times # drop NaN timestamps
mask &= ~np.isnan(times) # drop NaN timestamps (unparsable TIME cells)
if start is not None:
mask &= times >= float(start)
if stop is not None:
+9 -5
View File
@@ -1,14 +1,18 @@
import os
os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0"
import cv2
import orisys
import numpy as np
import time
import argparse
import time
import cv2
import numpy as np
import pyqtgraph as pg
from PyQt5.QtGui import QImage, QFont
from PyQt5.QtGui import QFont, QImage
from pyqtgraph.Qt import QtGui
import orisys
def make_gradient_brush(color_hex, max_alpha=150):
"""
创建一个从上到下渐变的笔刷 (兼容 PyQt5 和 PyQt6)