calibrate
This commit is contained in:
+40
-1
@@ -17,8 +17,9 @@ import numpy as np
|
||||
from app.config import Config
|
||||
from app.cv import blob as blob_codec
|
||||
from app.cv import resolver
|
||||
from app.cv.calibration import CalibrationOutcome, CalibrationPhoto, run_calibration
|
||||
from app.cv.comparison import PairMetrics, PairResult, compare_features
|
||||
from app.cv.exceptions import CvError, ImageDecodeFailed
|
||||
from app.cv.exceptions import CalibrationDatasetInvalid, CvError, ImageDecodeFailed
|
||||
from app.cv.extraction import Features, extract
|
||||
from app.cv.params import RequestSettings, parse_settings, validate_stored_settings
|
||||
|
||||
@@ -143,6 +144,44 @@ class CvService:
|
||||
|
||||
# ------------------------------------------------------------- internals
|
||||
|
||||
def calibrate(
|
||||
self,
|
||||
positive_parts: list[tuple[str, bytes]],
|
||||
negative_parts: list[tuple[str, bytes]],
|
||||
) -> CalibrationOutcome:
|
||||
"""Калибровка per-объектных настроек сравнения по двум пачкам фото
|
||||
(docs/08 §8.4; эндпоинт /api/v1/calibrate).
|
||||
|
||||
Битовые файлы пропускаются с записью в skipped; недостаток валидных
|
||||
фото — CalibrationDatasetInvalid. Извлечение — по env-умолчаниям:
|
||||
калибруются только параметры сравнения, пересчёт эталонов не нужен.
|
||||
"""
|
||||
extraction = resolver.effective_extraction(self.config, None)
|
||||
positives, skipped = self._load_calibration_pack(positive_parts, "positive", extraction)
|
||||
negatives, skipped_neg = self._load_calibration_pack(negative_parts, "negative", extraction)
|
||||
skipped += skipped_neg
|
||||
return run_calibration(positives, negatives, skipped, self.config)
|
||||
|
||||
@staticmethod
|
||||
def _load_calibration_pack(
|
||||
parts: list[tuple[str, bytes]], group: str, params
|
||||
) -> tuple[list[CalibrationPhoto], list[dict]]:
|
||||
loaded: list[CalibrationPhoto] = []
|
||||
skipped: list[dict] = []
|
||||
for name, data in parts:
|
||||
try:
|
||||
features = extract(data, params)
|
||||
except CvError as exc:
|
||||
skipped.append({"name": name, "group": group, "reason": str(exc)})
|
||||
continue
|
||||
loaded.append(
|
||||
CalibrationPhoto(
|
||||
name=name, group=group, index=-1, features=features,
|
||||
descriptors32=features.descriptors.astype(np.float32),
|
||||
)
|
||||
)
|
||||
return loaded, skipped
|
||||
|
||||
def _load_reference(
|
||||
self, part: bytes, index: int, settings_req: RequestSettings | None
|
||||
) -> tuple[Features, RequestSettings | None]:
|
||||
|
||||
Reference in New Issue
Block a user