RojakFace 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,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: RojakFace
3
+ Version: 0.1.0
4
+ Summary: A simple face detection and embedding package renamed to RojakFace
5
+ Author: Your Name
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: opencv-python
9
+ Requires-Dist: imgbeddings
10
+ Requires-Dist: numpy
11
+ Requires-Dist: Pillow
12
+ Requires-Dist: huggingface_hub
13
+ Requires-Dist: transformers
14
+ Requires-Dist: onnxruntime
15
+ Dynamic: author
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: requires-dist
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # RojakFace
23
+
24
+ A simple Python package for face detection and embedding.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ cd RojakFace
30
+ pip install .
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```python
36
+ from RojakFace import RojakFace
37
+
38
+ # Initialize
39
+ recognizer = RojakFace()
40
+
41
+ # Process
42
+ results = recognizer.process_image("my_image.jpg")
43
+
44
+ for face in results:
45
+ print(f"Detected face at: {face['box']}")
46
+ print(f"Embedding (768-d): {face['embedding'][:5]}...")
47
+ ```
@@ -0,0 +1,26 @@
1
+ # RojakFace
2
+
3
+ A simple Python package for face detection and embedding.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ cd RojakFace
9
+ pip install .
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```python
15
+ from RojakFace import RojakFace
16
+
17
+ # Initialize
18
+ recognizer = RojakFace()
19
+
20
+ # Process
21
+ results = recognizer.process_image("my_image.jpg")
22
+
23
+ for face in results:
24
+ print(f"Detected face at: {face['box']}")
25
+ print(f"Embedding (768-d): {face['embedding'][:5]}...")
26
+ ```
@@ -0,0 +1,4 @@
1
+ from .detector import RojakFace
2
+
3
+ __version__ = "0.1.0"
4
+ __all__ = ["RojakFace"]
@@ -0,0 +1,67 @@
1
+ import cv2
2
+ import numpy as np
3
+ import os
4
+ from PIL import Image
5
+ from imgbeddings import imgbeddings
6
+ import pkg_resources
7
+
8
+ class RojakFace:
9
+ def __init__(self):
10
+ """
11
+ Initializes the RojakFace recognizer with Haar Cascade and imgbeddings.
12
+ """
13
+ # Get path to the included haar cascade
14
+ cascade_name = "haarcascade_frontalface_default.xml"
15
+ self.cascade_path = pkg_resources.resource_filename(__name__, cascade_name)
16
+
17
+ if not os.path.exists(self.cascade_path):
18
+ # Fallback to current directory if not found in package
19
+ self.cascade_path = cascade_name
20
+
21
+ self.face_cascade = cv2.CascadeClassifier(self.cascade_path)
22
+ if self.face_cascade.empty():
23
+ raise IOError(f"Could not load face cascade from {self.cascade_path}")
24
+
25
+ self.ibed = imgbeddings()
26
+
27
+ def process_image(self, image_source):
28
+ """
29
+ Detects faces and returns 768-d embeddings.
30
+ image_source: can be a file path, bytes, or a numpy array.
31
+ """
32
+ if isinstance(image_source, str):
33
+ img = cv2.imread(image_source)
34
+ elif isinstance(image_source, bytes):
35
+ nparr = np.frombuffer(image_source, np.uint8)
36
+ img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
37
+ elif isinstance(image_source, np.ndarray):
38
+ img = image_source
39
+ else:
40
+ raise ValueError("Unsupported image source type")
41
+
42
+ if img is None:
43
+ return []
44
+
45
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
46
+ faces = self.face_cascade.detectMultiScale(
47
+ gray,
48
+ scaleFactor=1.1,
49
+ minNeighbors=5,
50
+ minSize=(30, 30)
51
+ )
52
+
53
+ results = []
54
+ for (x, y, w, h) in faces:
55
+ face_img = img[y:y+h, x:x+w]
56
+ face_pil = Image.fromarray(cv2.cvtColor(face_img, cv2.COLOR_BGR2RGB))
57
+
58
+ # Use the plural to_embeddings for compatibility
59
+ embedding = self.ibed.to_embeddings(face_pil)
60
+
61
+ results.append({
62
+ "box": [int(x), int(y), int(w), int(h)],
63
+ "embedding": embedding[0].tolist(),
64
+ "face_image": face_img
65
+ })
66
+
67
+ return results