(self, options: dict[str, str])
| 393 | self._antispoofer: Antispoofer | None = None |
| 394 | |
| 395 | def prepare(self, options: dict[str, str]) -> None: |
| 396 | raw_det = options.get("detector_onnx", "") |
| 397 | raw_rec = options.get("recognizer_onnx", "") |
| 398 | if not raw_det or not raw_rec: |
| 399 | raise ValueError( |
| 400 | "onnx_direct engine requires both detector_onnx and recognizer_onnx options" |
| 401 | ) |
| 402 | model_dir = options.get("_model_dir") |
| 403 | self.detector_path = _resolve_model_path(raw_det, model_dir=model_dir) |
| 404 | self.recognizer_path = _resolve_model_path(raw_rec, model_dir=model_dir) |
| 405 | self.input_size = _parse_det_size(options.get("det_size", "320x320")) |
| 406 | self.det_thresh = float(options.get("det_thresh", "0.5")) |
| 407 | self._antispoofer = _build_antispoofer(options, model_dir) |
| 408 | |
| 409 | # YuNet is a fixed-size detector; size is reset per detect() call to |
| 410 | # match the input frame. |
| 411 | self._detector = cv2.FaceDetectorYN.create( |
| 412 | self.detector_path, |
| 413 | "", |
| 414 | self.input_size, |
| 415 | score_threshold=self.det_thresh, |
| 416 | nms_threshold=0.3, |
| 417 | top_k=5000, |
| 418 | ) |
| 419 | self._recognizer = cv2.FaceRecognizerSF.create(self.recognizer_path, "") |
| 420 | |
| 421 | def detect(self, img: np.ndarray) -> list[FaceDetection]: |
| 422 | if self._detector is None: |
nothing calls this directly
no test coverage detected