faceswitch 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- faceswitch/__init__.py +9 -0
- faceswitch/core/__init__.py +6 -0
- faceswitch/core/interfaces.py +26 -0
- faceswitch/core/types.py +14 -0
- faceswitch/detectors/__init__.py +5 -0
- faceswitch/detectors/hog/__init__.py +6 -0
- faceswitch/detectors/hog/config.py +10 -0
- faceswitch/detectors/hog/detector.py +49 -0
- faceswitch/py.typed +0 -0
- faceswitch-0.1.0.dist-info/METADATA +64 -0
- faceswitch-0.1.0.dist-info/RECORD +14 -0
- faceswitch-0.1.0.dist-info/WHEEL +5 -0
- faceswitch-0.1.0.dist-info/licenses/LICENSE +21 -0
- faceswitch-0.1.0.dist-info/top_level.txt +1 -0
faceswitch/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Public FaceSwitch library API."""
|
|
2
|
+
|
|
3
|
+
from faceswitch.core.interfaces import FaceDetector
|
|
4
|
+
from faceswitch.core.types import FaceBox
|
|
5
|
+
from faceswitch.detectors.hog import HogDetector, HogDetectorConfig
|
|
6
|
+
|
|
7
|
+
__all__ = ["FaceBox", "FaceDetector", "HogDetector", "HogDetectorConfig"]
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
import numpy as np
|
|
8
|
+
from numpy.typing import NDArray
|
|
9
|
+
|
|
10
|
+
from faceswitch.core.types import FaceBox
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FaceDetector(ABC):
|
|
14
|
+
"""Contract for face detector implementations."""
|
|
15
|
+
|
|
16
|
+
@abstractmethod
|
|
17
|
+
def detect(self, image: "NDArray[np.uint8]") -> list[FaceBox]:
|
|
18
|
+
"""Return detected faces from a numpy image array.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
image: Input image as numpy array (uint8, grayscale or BGR/RGB).
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
List of FaceBox objects containing detected face locations.
|
|
25
|
+
"""
|
|
26
|
+
raise NotImplementedError
|
faceswitch/core/types.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from numpy.typing import NDArray
|
|
5
|
+
|
|
6
|
+
from faceswitch.core.interfaces import FaceDetector
|
|
7
|
+
from faceswitch.core.types import FaceBox
|
|
8
|
+
from faceswitch.detectors.hog.config import HogDetectorConfig
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class HogDetector(FaceDetector):
|
|
12
|
+
"""HOG-based frontal face detector using dlib."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, config: HogDetectorConfig | None = None) -> None:
|
|
15
|
+
"""Initialize and cache dlib's frontal face detector."""
|
|
16
|
+
try:
|
|
17
|
+
import dlib # type: ignore
|
|
18
|
+
except ImportError as exc:
|
|
19
|
+
raise ImportError(
|
|
20
|
+
"HogDetector requires optional dependency 'dlib'. "
|
|
21
|
+
"Install with: pip install 'faceswitch[hog]'"
|
|
22
|
+
) from exc
|
|
23
|
+
|
|
24
|
+
self.config = config or HogDetectorConfig()
|
|
25
|
+
self._detector = dlib.get_frontal_face_detector()
|
|
26
|
+
|
|
27
|
+
def detect(self, image: NDArray[np.uint8]) -> list[FaceBox]:
|
|
28
|
+
"""Detect faces from a numpy ndarray (uint8, grayscale or BGR/RGB image)."""
|
|
29
|
+
if image is None:
|
|
30
|
+
return []
|
|
31
|
+
|
|
32
|
+
if len(image.shape) == 3:
|
|
33
|
+
gray = (
|
|
34
|
+
0.114 * image[:, :, 0] + 0.587 * image[:, :, 1] + 0.299 * image[:, :, 2]
|
|
35
|
+
).astype("uint8")
|
|
36
|
+
else:
|
|
37
|
+
gray = image
|
|
38
|
+
|
|
39
|
+
detections = self._detector(gray, self.config.upsample_times)
|
|
40
|
+
return [
|
|
41
|
+
FaceBox(
|
|
42
|
+
x1=int(face.left()),
|
|
43
|
+
y1=int(face.top()),
|
|
44
|
+
x2=int(face.right()),
|
|
45
|
+
y2=int(face.bottom()),
|
|
46
|
+
confidence=None,
|
|
47
|
+
)
|
|
48
|
+
for face in detections
|
|
49
|
+
]
|
faceswitch/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: faceswitch
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Simple multi-model face detection library
|
|
5
|
+
Author: FaceSwitch Contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/yourusername/faceswitch
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/yourusername/faceswitch/issues
|
|
9
|
+
Project-URL: Documentation, https://github.com/yourusername/faceswitch/blob/main/README.md
|
|
10
|
+
Keywords: face-detection,computer-vision,hog,dlib
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Provides-Extra: hog
|
|
24
|
+
Requires-Dist: dlib>=19.24; extra == "hog"
|
|
25
|
+
Provides-Extra: examples
|
|
26
|
+
Requires-Dist: opencv-python>=4.8; extra == "examples"
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# FaceSwitch
|
|
32
|
+
|
|
33
|
+
FaceSwitch is an installable Python library for face detection backends.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install -e .
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Install the HOG backend dependency:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install -e '.[hog]'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Minimal Usage
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import cv2
|
|
51
|
+
from faceswitch import HogDetector
|
|
52
|
+
|
|
53
|
+
image = cv2.imread("tests/Lenna_test_image.png")
|
|
54
|
+
detector = HogDetector()
|
|
55
|
+
faces = detector.detect(image)
|
|
56
|
+
print(f"Detected: {len(faces)}")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Example Script
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install -e '.[hog,examples]'
|
|
63
|
+
python examples/demo_hog.py tests/Lenna_test_image.png
|
|
64
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
faceswitch/__init__.py,sha256=CfMUboGJXNY-jAYow2WGLc2pFHIE3nSd_YsFsKkVaIE,297
|
|
2
|
+
faceswitch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
faceswitch/core/__init__.py,sha256=oX4Jx0RnS8D7OTOOfasbX7OJ6m1xhIH5fOE8L1rjHHw,195
|
|
4
|
+
faceswitch/core/interfaces.py,sha256=brbsKWNez65PCKfDD7Nd7cs2Njh4EYdg9IqTMiw2aQo,703
|
|
5
|
+
faceswitch/core/types.py,sha256=nTrzwxnmlhqU47bZ-Vuot0Fix3oeue45IP_C0jbW-lA,240
|
|
6
|
+
faceswitch/detectors/__init__.py,sha256=fW0Ym2U0tbJTZDaZ-h9V2qVZpomgnrTYoAC9f4JdM1w,149
|
|
7
|
+
faceswitch/detectors/hog/__init__.py,sha256=4zGIkQBGFT64eGiitXCK37ByPmkMn2zX2CNqJ0b85ew,197
|
|
8
|
+
faceswitch/detectors/hog/config.py,sha256=l7QAPqQMBnhdpC-Sv5wRNc_UqbOS-3h__fM5xE3Rtyw,197
|
|
9
|
+
faceswitch/detectors/hog/detector.py,sha256=Fs-UVMQzKZf0ejI8z_yGr1zdok1ylbpq-Bqm6dVP9wU,1620
|
|
10
|
+
faceswitch-0.1.0.dist-info/licenses/LICENSE,sha256=u3OZilfgdcUEli-0GiNoTHjfcBN7kPAGGa0W0Yf1wck,1067
|
|
11
|
+
faceswitch-0.1.0.dist-info/METADATA,sha256=hP8ctXwQ_YU-Qrr4JmoFuhSQ3pIzxNlMsb-ohvuYFrc,1778
|
|
12
|
+
faceswitch-0.1.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
13
|
+
faceswitch-0.1.0.dist-info/top_level.txt,sha256=uwNxCDMFWivgtcpl3RhrH4DDfegs2i4Arh4SFXucuB0,11
|
|
14
|
+
faceswitch-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohsin Ali
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
faceswitch
|