ruminasval commited on
Commit
13ad7ff
·
verified ·
1 Parent(s): 09c1e1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
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
- x1 = int(bbox.xmin * w)
48
- y1 = int(bbox.ymin * h)
49
- x2 = int((bbox.xmin + bbox.width) * w)
50
- y2 = int((bbox.ymin + bbox.height) * h)
 
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")