Saad0KH commited on
Commit
26e18b2
Β·
verified Β·
1 Parent(s): 7713aa5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -47,22 +47,22 @@ def detect_person(image):
47
  if bboxes.shape[0] == 0: # Aucun visage dΓ©tectΓ©
48
  return []
49
 
 
 
50
  bboxes = np.round(bboxes[:, :4]).astype(int)
51
- kpss = np.round(kpss).astype(int)
52
- kpss[:, :, 0] = np.clip(kpss[:, :, 0], 0, img.shape[1])
53
- kpss[:, :, 1] = np.clip(kpss[:, :, 1], 0, img.shape[0])
54
- vbboxes = bboxes.copy()
55
- vbboxes[:, 0] = kpss[:, 0, 0]
56
- vbboxes[:, 1] = kpss[:, 0, 1]
57
- vbboxes[:, 2] = kpss[:, 4, 0]
58
- vbboxes[:, 3] = kpss[:, 4, 1]
59
 
60
  person_images = []
61
  for i in range(bboxes.shape[0]):
62
  bbox = bboxes[i]
63
  x1, y1, x2, y2 = bbox
64
  person_img = img[y1:y2, x1:x2]
65
-
66
  # Convert numpy array to PIL Image and encode to base64
67
  pil_img = Image.fromarray(person_img[:, :, ::-1]) # BGR -> RGB
68
  base64_img = encode_image_to_base64(pil_img)
@@ -83,7 +83,6 @@ def detect():
83
  except Exception as e:
84
  return jsonify({'error': str(e)}), 500
85
 
86
-
87
  def segment_image(img, clothes):
88
  img = decode_image_from_base64(img)
89
  return segment_clothing(img, clothes)
 
47
  if bboxes.shape[0] == 0: # Aucun visage dΓ©tectΓ©
48
  return []
49
 
50
+ height, width, _ = img.shape # Get image dimensions
51
+
52
  bboxes = np.round(bboxes[:, :4]).astype(int)
53
+
54
+ # Clamp bounding boxes within image boundaries
55
+ bboxes[:, 0] = np.clip(bboxes[:, 0], 0, width) # x1
56
+ bboxes[:, 1] = np.clip(bboxes[:, 1], 0, height) # y1
57
+ bboxes[:, 2] = np.clip(bboxes[:, 2], 0, width) # x2
58
+ bboxes[:, 3] = np.clip(bboxes[:, 3], 0, height) # y2
 
 
59
 
60
  person_images = []
61
  for i in range(bboxes.shape[0]):
62
  bbox = bboxes[i]
63
  x1, y1, x2, y2 = bbox
64
  person_img = img[y1:y2, x1:x2]
65
+
66
  # Convert numpy array to PIL Image and encode to base64
67
  pil_img = Image.fromarray(person_img[:, :, ::-1]) # BGR -> RGB
68
  base64_img = encode_image_to_base64(pil_img)
 
83
  except Exception as e:
84
  return jsonify({'error': str(e)}), 500
85
 
 
86
  def segment_image(img, clothes):
87
  img = decode_image_from_base64(img)
88
  return segment_clothing(img, clothes)