faceswitch 0.1.0__tar.gz

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.
@@ -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,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,34 @@
1
+ # FaceSwitch
2
+
3
+ FaceSwitch is an installable Python library for face detection backends.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install -e .
9
+ ```
10
+
11
+ Install the HOG backend dependency:
12
+
13
+ ```bash
14
+ pip install -e '.[hog]'
15
+ ```
16
+
17
+ ## Minimal Usage
18
+
19
+ ```python
20
+ import cv2
21
+ from faceswitch import HogDetector
22
+
23
+ image = cv2.imread("tests/Lenna_test_image.png")
24
+ detector = HogDetector()
25
+ faces = detector.detect(image)
26
+ print(f"Detected: {len(faces)}")
27
+ ```
28
+
29
+ ## Example Script
30
+
31
+ ```bash
32
+ pip install -e '.[hog,examples]'
33
+ python examples/demo_hog.py tests/Lenna_test_image.png
34
+ ```
@@ -0,0 +1,49 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "faceswitch"
7
+ version = "0.1.0"
8
+ description = "Simple multi-model face detection library"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [{ name = "FaceSwitch Contributors" }]
13
+ keywords = ["face-detection", "computer-vision", "hog", "dlib"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Scientific/Engineering :: Image Recognition",
23
+ "Topic :: Software Development :: Libraries :: Python Modules",
24
+ ]
25
+ dependencies = []
26
+
27
+ [project.urls]
28
+ "Homepage" = "https://github.com/yourusername/faceswitch"
29
+ "Bug Tracker" = "https://github.com/yourusername/faceswitch/issues"
30
+ "Documentation" = "https://github.com/yourusername/faceswitch/blob/main/README.md"
31
+
32
+ [project.optional-dependencies]
33
+ hog = ["dlib>=19.24"]
34
+ examples = ["opencv-python>=4.8"]
35
+ dev = ["pytest>=8.0"]
36
+
37
+ [tool.setuptools]
38
+ package-dir = {"" = "src"}
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["src"]
42
+ include = ["faceswitch*"]
43
+
44
+ [tool.pytest.ini_options]
45
+ testpaths = ["tests"]
46
+ addopts = "-q"
47
+
48
+ [tool.setuptools.package-data]
49
+ faceswitch = ["py.typed"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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,6 @@
1
+ """Core contracts and types for detector implementations."""
2
+
3
+ from faceswitch.core.interfaces import FaceDetector
4
+ from faceswitch.core.types import FaceBox
5
+
6
+ __all__ = ["FaceBox", "FaceDetector"]
@@ -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
@@ -0,0 +1,14 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass(frozen=True)
7
+ class FaceBox:
8
+ """Face bounding box in xyxy format."""
9
+
10
+ x1: int
11
+ y1: int
12
+ x2: int
13
+ y2: int
14
+ confidence: float | None = None
@@ -0,0 +1,5 @@
1
+ """Detector implementations."""
2
+
3
+ from faceswitch.detectors.hog import HogDetector, HogDetectorConfig
4
+
5
+ __all__ = ["HogDetector", "HogDetectorConfig"]
@@ -0,0 +1,6 @@
1
+ """HOG detector package."""
2
+
3
+ from faceswitch.detectors.hog.config import HogDetectorConfig
4
+ from faceswitch.detectors.hog.detector import HogDetector
5
+
6
+ __all__ = ["HogDetector", "HogDetectorConfig"]
@@ -0,0 +1,10 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass(frozen=True)
7
+ class HogDetectorConfig:
8
+ """Configuration for dlib HOG detector."""
9
+
10
+ upsample_times: int = 1
@@ -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
+ ]
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,19 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/faceswitch/__init__.py
5
+ src/faceswitch/py.typed
6
+ src/faceswitch.egg-info/PKG-INFO
7
+ src/faceswitch.egg-info/SOURCES.txt
8
+ src/faceswitch.egg-info/dependency_links.txt
9
+ src/faceswitch.egg-info/requires.txt
10
+ src/faceswitch.egg-info/top_level.txt
11
+ src/faceswitch/core/__init__.py
12
+ src/faceswitch/core/interfaces.py
13
+ src/faceswitch/core/types.py
14
+ src/faceswitch/detectors/__init__.py
15
+ src/faceswitch/detectors/hog/__init__.py
16
+ src/faceswitch/detectors/hog/config.py
17
+ src/faceswitch/detectors/hog/detector.py
18
+ tests/test_hog_detector.py
19
+ tests/test_public_api.py
@@ -0,0 +1,9 @@
1
+
2
+ [dev]
3
+ pytest>=8.0
4
+
5
+ [examples]
6
+ opencv-python>=4.8
7
+
8
+ [hog]
9
+ dlib>=19.24
@@ -0,0 +1 @@
1
+ faceswitch
@@ -0,0 +1,34 @@
1
+ import importlib.util
2
+ from pathlib import Path
3
+
4
+ import pytest
5
+
6
+ from faceswitch import HogDetector
7
+
8
+
9
+ def test_hog_detector_optional_dependency_behavior() -> None:
10
+ has_dlib = importlib.util.find_spec("dlib") is not None
11
+
12
+ if has_dlib:
13
+ detector = HogDetector()
14
+ assert detector is not None
15
+ else:
16
+ try:
17
+ HogDetector()
18
+ assert False, "Expected ImportError when dlib is missing"
19
+ except ImportError as exc:
20
+ assert "faceswitch[hog]" in str(exc)
21
+
22
+
23
+ def test_hog_detector_detects_lenna_face() -> None:
24
+ pytest.importorskip("dlib")
25
+ cv2 = pytest.importorskip("cv2")
26
+
27
+ image_path = Path(__file__).parent / "assets" / "Lenna_test_image.png"
28
+ image = cv2.imread(str(image_path))
29
+ assert image is not None, f"Could not read test image: {image_path}"
30
+
31
+ detector = HogDetector()
32
+ faces = detector.detect(image)
33
+
34
+ assert len(faces) >= 1
@@ -0,0 +1,7 @@
1
+ from faceswitch import FaceBox, FaceDetector, HogDetector
2
+
3
+
4
+ def test_public_api_exports_classes() -> None:
5
+ assert isinstance(FaceBox, type)
6
+ assert isinstance(FaceDetector, type)
7
+ assert isinstance(HogDetector, type)