Metadata-Version: 2.4
Name: face-matching-king
Version: 0.1.0
Summary: High-accuracy face matching library for comparing faces from images, files, or base64 strings.
Author: Raja Kaushal
License: MIT License
        
        Copyright (c) 2026 Raja Kaushal
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/raja-kaushal/face-matching-king
Project-URL: Issues, https://github.com/raja-kaushal/face-matching-king/issues
Keywords: face-matching,face-recognition,insightface,biometrics,computer-vision
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: insightface>=0.7
Requires-Dist: opencv-python>=4.8
Requires-Dist: numpy>=1.24
Requires-Dist: onnxruntime>=1.16
Provides-Extra: gpu
Requires-Dist: onnxruntime-gpu>=1.16; extra == "gpu"
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Dynamic: license-file

# 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

```bash
pip install face-matching-king
```

> **GPU support** (CUDA): install with the `gpu` extra to get `onnxruntime-gpu`:
> ```bash
> pip install "face-matching-king[gpu]"
> ```

---

## Quick Start

```python
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
