High-accuracy face matching library for comparing faces from images, files, or base64 strings.
Project description
face-matching-king
A simple, high-accuracy face matching library for verifying whether two face images belong to the same person.
Compare faces from file paths, numpy arrays, or base64 strings with a single method call.
Installation
pip install face-matching-king
GPU support (CUDA): install with the
gpuextra to getonnxruntime-gpu:pip install "face-matching-king[gpu]"
Quick Start
from face_matching_king import FaceMatcher
matcher = FaceMatcher() # loads InsightFace model once
# --- from file paths ---
result = matcher.match_from_path("photo.jpg", "id_card.jpg")
# --- from numpy arrays (BGR, OpenCV format) ---
import cv2
img1 = cv2.imread("photo.jpg")
img2 = cv2.imread("id_card.jpg")
result = matcher.match(img1, img2)
# --- from base64 strings (raw or data-URI) ---
result = matcher.match_from_base64(base64_str_1, base64_str_2)
print(result)
# <MatchResult MATCH | similarity=0.82 | threshold=0.25>
print(result.to_dict())
# {
# "similarity": 0.82,
# "raw_similarity": 0.67,
# "match": True,
# "threshold": 0.25,
# "remark": "Recommended threshold is 0.25 ..."
# }
API Reference
FaceMatcher(threshold=0.25, det_size=(640,640), providers=[...])
| Parameter | Type | Default | Description |
|---|---|---|---|
threshold |
float |
0.25 |
Similarity cut-off for match/no-match |
det_size |
(int, int) |
(640, 640) |
Face detector input resolution |
providers |
list[str] |
["CUDAExecutionProvider","CPUExecutionProvider"] |
ONNX Runtime execution providers |
Methods
| Method | Input | Description |
|---|---|---|
match(img1, img2) |
np.ndarray (BGR) |
Compare two OpenCV images |
match_from_path(p1, p2) |
str | Path |
Compare two image files |
match_from_base64(b1, b2) |
str |
Compare two base64 strings or data-URIs |
All methods accept an optional threshold keyword to override the instance default for a single call.
MatchResult
| Field | Type | Description |
|---|---|---|
similarity |
float |
Human-friendly score 0.0 – 1.0 |
raw_similarity |
float |
Raw cosine similarity -1.0 – 1.0 |
match |
bool |
True if similarity >= threshold |
threshold |
float |
Threshold used for this comparison |
remark |
str |
Short human-readable note |
Threshold Guide
| Threshold | Use case |
|---|---|
0.20 |
Very lenient – allow partial matches |
0.25 |
Default – recommended for most ID verification |
0.40 |
Strict – near-identical photos only |
License
MIT © Raja Kaushal
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file face_matching_king-0.1.0.tar.gz.
File metadata
- Download URL: face_matching_king-0.1.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
009ac9d32cfcdceedd56cd317c24c5b1cfbe1fad3e37c7c92388c8664ba87fac
|
|
| MD5 |
a7808a16f8631be7da29c728119d4498
|
|
| BLAKE2b-256 |
4b5c666e1ca41d2a326b68daf15dc6eb4043100db7653cb18f074e089543d65a
|
File details
Details for the file face_matching_king-0.1.0-py3-none-any.whl.
File metadata
- Download URL: face_matching_king-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce2fe1a7146a98eecf25fda5a2fcdec0b44041e65d3326e5f61c83116762ad53
|
|
| MD5 |
a4e55185065e4f2df1a9fc2727280337
|
|
| BLAKE2b-256 |
c69a2a6437550f7dbe7b0808934138c9b566fa7c6c98241a20b69fd672302ca1
|