amirgame197 commited on
Commit
b22fdc9
1 Parent(s): 4ae29be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -8,8 +8,22 @@ def blur_image(image_path, detections, parts_to_blur):
8
  for detection in detections:
9
  label = detection['class']
10
  if label in parts_to_blur:
11
- x1, y1, x2, y2 = map(int, detection['box'])
 
 
 
 
 
 
 
 
 
12
  roi = image[y1:y2, x1:x2]
 
 
 
 
 
13
  roi = cv2.GaussianBlur(roi, (51, 51), 30)
14
  image[y1:y2, x1:x2] = roi
15
 
 
8
  for detection in detections:
9
  label = detection['class']
10
  if label in parts_to_blur:
11
+ x, y, width, height = map(int, detection['box'])
12
+ x1, y1 = x, y
13
+ x2, y2 = x + width, y + height
14
+
15
+ x1 = max(0, x1)
16
+ y1 = max(0, y1)
17
+ x2 = min(image.shape[1], x2)
18
+ y2 = min(image.shape[0], y2)
19
+
20
+ print(f"Blurring region: {x1, y1, x2, y2} for label: {label}")
21
  roi = image[y1:y2, x1:x2]
22
+
23
+ if roi.size == 0:
24
+ print(f"Skipping empty ROI for detection: {detection}")
25
+ continue
26
+
27
  roi = cv2.GaussianBlur(roi, (51, 51), 30)
28
  image[y1:y2, x1:x2] = roi
29