Skip to content

Biometric Kernel

The BiometricKernel is the top-level entry point for the OpenBiometrics engine. It owns the lifecycle of all processing modules and provides a unified interface for initialization, health checks, and access to each subsystem.

from openbiometrics import BiometricKernel, BiometricConfig, FaceConfig
config = BiometricConfig(
face=FaceConfig(models_dir="./models", ctx_id=0),
)
kernel = BiometricKernel(config)
kernel.load()
# Process an image
results = kernel.face.process(image)
for r in results:
print(f"Age: {r.age}, Gender: {r.gender}, Live: {r.is_live}")

BiometricConfig is the top-level dataclass. Each module has its own config section.

from openbiometrics.config import (
BiometricConfig,
FaceConfig,
DocumentConfig,
LivenessConfig,
PersonConfig,
VideoConfig,
EventsConfig,
IdentityConfig,
)
config = BiometricConfig(
face=FaceConfig(...),
document=DocumentConfig(...),
liveness=LivenessConfig(...),
person=PersonConfig(...),
video=VideoConfig(...),
events=EventsConfig(...),
identity=IdentityConfig(...),
)

Core face processing. Always loaded.

FieldTypeDefaultDescription
models_dirstr"./models"Path to model files
ctx_idint0GPU device index (-1 for CPU)
det_threshfloat0.5Detection confidence threshold
det_sizetuple[int, int](640, 640)Detection input resolution
max_facesint0Max faces to detect (0 = unlimited)
enable_livenessboolTrueEnable passive liveness scoring
enable_demographicsboolTrueEnable age/gender estimation
enable_qualityboolTrueEnable face quality assessment
quality_gateboolFalseSkip recognition if quality check fails

Requires the document extra (pip install openbiometrics-engine[document]).

FieldTypeDefaultDescription
enabledboolTrueEnable document processing
models_dirstr"./models"Path to document model files
ctx_idint0GPU device index
enable_ocrboolTrueEnable OCR text extraction
enable_mrzboolTrueEnable MRZ parsing
enable_face_extractionboolFalseExtract face photo from document

Requires the liveness extra (pip install openbiometrics-engine[liveness]). This configures the interactive active liveness system. For passive liveness (single-image), use FaceConfig.enable_liveness.

FieldTypeDefaultDescription
enabledboolTrueEnable active liveness sessions
models_dirstr"./models"Path to liveness model files
ctx_idint0GPU device index
session_ttlfloat300.0Session time-to-live in seconds
num_challengesint3Number of challenges per session
timeout_secondsfloat5.0Per-challenge timeout

Requires the person extra (pip install openbiometrics-engine[person]).

FieldTypeDefaultDescription
enabledboolTrueEnable person detection/tracking
models_dirstr"./models"Path to model files
ctx_idint0GPU device index
model_pathstr"yolov8n.pt"YOLO model file
confidence_thresholdfloat0.5Detection confidence threshold
max_disappearedint30Frames before a tracked person is dropped
iou_thresholdfloat0.3IoU threshold for tracker matching
FieldTypeDefaultDescription
enabledboolTrueEnable video stream processing
max_fpsfloat30.0Maximum processing FPS
track_facesboolTrueEnable face tracking across frames
buffer_sizeint30Frame buffer size
FieldTypeDefaultDescription
enabledboolTrueEnable event bus
max_workersint4Thread pool size for event dispatch
history_sizeint1000Number of recent events to retain
webhooks_enabledboolTrueEnable webhook dispatch
FieldTypeDefaultDescription
enabledboolTrueEnable identity resolution
watchlist_dirstr"./watchlists"Watchlist storage directory
cluster_thresholdfloat0.6Cosine similarity threshold for clustering

The kernel uses guarded imports for optional modules. If a dependency is not installed, the corresponding module is silently set to None:

kernel = BiometricKernel(BiometricConfig(
document=DocumentConfig(enabled=True),
person=PersonConfig(enabled=False),
))
kernel.load()
# Document module loads if python-doctr is installed
print(kernel.document) # DocumentPipeline or None
# Person module is disabled in config, not loaded
print(kernel.person) # None

This means you can always safely check:

if kernel.document is not None:
result = kernel.document.scan(image)

After calling kernel.load(), access modules through properties:

PropertyTypeDescription
kernel.faceFacePipelineFace detection, recognition, quality, demographics, liveness
kernel.documentDocumentPipeline | NoneDocument detection, OCR, MRZ
kernel.livenessActiveLivenessManager | NoneInteractive liveness sessions
kernel.person_detectorPersonDetector | NoneYOLO-based person detection
kernel.person_trackerPersonTracker | NoneIoU-based multi-person tracking
kernel.camerasCameraManager | NoneMulti-stream camera management
kernel.eventsEventBus | NonePub/sub event bus
kernel.webhooksWebhookDispatcher | NoneWebhook forwarding
kernel.identity_resolverIdentityResolver | NoneCross-watchlist identity resolution
kernel.clustererFaceClusterer | NoneFace embedding deduplication

The kernel provides a structured health check:

status = kernel.health()
print(status.healthy) # True if face module is operational
print(status.modules) # {"face": True, "document": True, ...}
print(status.details) # {"face": "loaded: detector, recognizer, liveness", ...}

healthy is True when the face module is operational. Other modules may be disabled or missing dependencies without affecting overall health.

kernel = BiometricKernel(config)
# Load all configured modules (safe to call multiple times)
kernel.load()
# ... process images ...
# Shut down cleanly (stops cameras, event bus, webhooks)
kernel.shutdown()

load() is idempotent — calling it again after the first successful load is a no-op. shutdown() gracefully stops all running background services.