Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,10 +44,11 @@ def preprocess_image(image):
|
|
44 |
detection = results.detections[0]
|
45 |
bbox = detection.location_data.relative_bounding_box
|
46 |
h, w, _ = image.shape
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
51 |
image = image[y1:y2, x1:x2]
|
52 |
else:
|
53 |
raise ValueError("No face detected")
|
|
|
44 |
detection = results.detections[0]
|
45 |
bbox = detection.location_data.relative_bounding_box
|
46 |
h, w, _ = image.shape
|
47 |
+
# In the face cropping section
|
48 |
+
x1 = max(0, int(bbox.xmin * w))
|
49 |
+
y1 = max(0, int(bbox.ymin * h))
|
50 |
+
x2 = min(w, int((bbox.xmin + bbox.width) * w))
|
51 |
+
y2 = min(h, int((bbox.ymin + bbox.height) * h))
|
52 |
image = image[y1:y2, x1:x2]
|
53 |
else:
|
54 |
raise ValueError("No face detected")
|