moca-face-matcher
Ultra-fast face matching library using OpenCV's YuNet for detection, SFace for recognition, and FAISS for high-performance vector search. Designed as both a production-grade SDK and a powerful CLI tool.
Features
- Blazing Fast: Integrated with FAISS for near-instant search in large databases.
- State-of-the-Art Models: Uses YuNet (fastest detection) and SFace (robust recognition).
- GPU Ready: Hardware acceleration support via OpenCV DNN/CUDA.
- Developer First: Clean SDK interface with strict type hinting (Mypy) and JSON-based secure cache.
- Secure by Design: Automatic SHA-256 model verification and no insecure serialization (no
pickle). - Portable Cache: Uses relative paths in the JSON cache, making it portable across different machines.
Requirements
- Python 3.9 or superior.
- Internet connection for the first run (downloads ~40 MB of ONNX models from OpenCV Zoo).
Installation
pip install moca-face-matcher
For local development:
git clone https://github.com/Moca9801/face-match.git
cd face-match
pip install -e ".[dev]"
Usage
Command Line Interface (CLI)
Search for a face in a gallery folder:
face-match path/to/query.jpg --db path/to/gallery/
Library Usage (SDK)
The core function is find_matches. It returns a structured dictionary and does not print to the console, making it ideal for integration into other systems.
from pathlib import Path
from face_match import find_matches
results = find_matches(
query=Path("query.jpg"),
db=Path("./gallery"),
top=3,
threshold=0.4
)
print(f"Scanned {results['total_scanned']} images.")
for match in results['results']:
print(f"Match found: {match['path']} (Distance: {match['distance']})")
CLI vs SDK Mapping
| CLI Option | SDK Parameter (find_matches) |
Description |
|---|---|---|
query |
query (Path) |
Path to the query image. |
--db |
db (Path) |
Path to the gallery/database folder. |
--top |
top (int) |
Number of results to return. |
--metric |
distance (int) |
0 for Cosine (default), 1 for L2. |
--threshold |
threshold (float) |
Similarity threshold. |
--device |
device (str) |
cpu (default) or gpu. |
--rebuild |
rebuild_cache (bool) |
Force rescan of all images. |
Technical Details
Metrics and Thresholds
The library uses predefined thresholds based on the SFace model's official recommendations:
- Cosine Similarity (
--metric coseno): Matches range from-1to1. Higher is better. Recommended threshold:0.363. - L2 Distance (
--metric l2): Matches start from0. Lower is better. Recommended threshold:1.128.
Development and Testing
Contributors are welcome! To run quality checks locally:
# Run Linting
ruff check src tests
# Run Type Checking
mypy src/face_match
# Run Tests
pytest
Security and Data Privacy
Disclaimer
- This software is not a certified biometric identification system.
- It is intended for research and low-risk identification tasks.
- The author is not responsible for misuse or legal implications of using biometric data.
Versión en Español (Resumen)
moca-face-matcher es una librería de búsqueda de coincidencias faciales ultra rápida.
Instalación rápida
pip install moca-face-matcher
Características
- Búsqueda vectorial con FAISS.
- Modelos YuNet + SFace.
- Soporte para GPU.
- Caché segura en JSON con rutas relativas.
Seguridad
Este software maneja datos biométricos. El archivo de caché .face_embeddings_cache.json es sensible y no debe ser compartido.
License
Distributed under the MIT License. See LICENSE for more information.
Metadata
Release files for moca-face-matcher 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| moca_face_matcher-0.2.2.tar.gz | 16.1 kB | Without provenance | Details for moca_face_matcher-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| moca_face_matcher-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for moca_face_matcher-0.2.2-py3-none-any.whl |
Total release size: 27.5 kB
Release files / moca_face_matcher-0.2.2.tar.gz
| Download URL | moca_face_matcher-0.2.2.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5719f9c811ab3e101f3dee2e2dbc9cf819a379b8fa86790c75523897a510b06e
|
|
BLAKE2b-256 checksum How to use checksums |
25c5d24993520565500ca24941d9cc5b1e1e83d6ea332a2a56fb53e3117b90c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / moca_face_matcher-0.2.2-py3-none-any.whl
| Download URL | moca_face_matcher-0.2.2-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7a33538aa3564a65f795c12a6a5c7aac648f6867e2af1aa1439c10b9f108c03
|
|
BLAKE2b-256 checksum How to use checksums |
28ba9d88a6414fb23b292078b1bfd5eaf7fdfb0bf5574f13e11c722898b59915
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for moca-face-matcher 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.