3morrrrr commited on
Commit
0aee31b
·
verified ·
1 Parent(s): 45b5364

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -18
app.py CHANGED
@@ -80,33 +80,23 @@ def process_image(image, text):
80
 
81
  # Iterate over detected objects
82
  for obj in prediction['predictions']:
83
- x1 = int(obj['x'] - obj['width'] / 2)
84
- y1 = int(obj['y'] - obj['height'] / 2)
85
- x2 = int(obj['x'] + obj['width'] / 2)
86
- y2 = int(obj['y'] + obj['height'] / 2)
87
-
88
- logging.debug(f"Bounding box coordinates: ({x1}, {y1}), ({x2}, {y2}).")
89
-
90
- # Detect the angle of the paper
91
- angle = detect_paper_angle(np.array(image), (x1, y1, x2, y2))
92
- logging.debug(f"Detected paper angle: {angle} degrees.")
93
-
94
- # Adjust dimensions based on white paper detection
95
  white_paper_width = obj['width']
96
  white_paper_height = obj['height']
97
 
98
- padding_x = int(white_paper_width * 0.05) # 5% padding horizontally
99
- padding_y = int(white_paper_height * 0.05) # 5% padding vertically
 
 
 
 
100
 
 
101
  x1_padded = int(obj['x'] - white_paper_width / 2 + padding_x)
102
  y1_padded = int(obj['y'] - white_paper_height / 2 + padding_y)
103
  x2_padded = int(obj['x'] + white_paper_width / 2 - padding_x)
104
  y2_padded = int(obj['y'] + white_paper_height / 2 - padding_y)
105
 
106
- box_width = x2_padded - x1_padded
107
- box_height = y2_padded - y1_padded
108
- logging.debug(f"Padded white paper dimensions: width={box_width}, height={box_height}.")
109
-
110
  # Draw bounding box for debugging purposes
111
  debug_layer = pil_image.copy()
112
  debug_draw = ImageDraw.Draw(debug_layer)
@@ -240,3 +230,4 @@ if __name__ == "__main__":
240
 
241
 
242
 
 
 
80
 
81
  # Iterate over detected objects
82
  for obj in prediction['predictions']:
83
+ # Use white paper dimensions
 
 
 
 
 
 
 
 
 
 
 
84
  white_paper_width = obj['width']
85
  white_paper_height = obj['height']
86
 
87
+ padding_x = int(white_paper_width * 0.2) # 5% padding horizontally
88
+ padding_y = int(white_paper_height * 0.2) # 5% padding vertically
89
+
90
+ box_width = white_paper_width - 2 * padding_x
91
+ box_height = white_paper_height - 2 * padding_y
92
+ logging.debug(f"Padded white paper dimensions: width={box_width}, height={box_height}.")
93
 
94
+ # Calculate padded coordinates
95
  x1_padded = int(obj['x'] - white_paper_width / 2 + padding_x)
96
  y1_padded = int(obj['y'] - white_paper_height / 2 + padding_y)
97
  x2_padded = int(obj['x'] + white_paper_width / 2 - padding_x)
98
  y2_padded = int(obj['y'] + white_paper_height / 2 - padding_y)
99
 
 
 
 
 
100
  # Draw bounding box for debugging purposes
101
  debug_layer = pil_image.copy()
102
  debug_draw = ImageDraw.Draw(debug_layer)
 
230
 
231
 
232
 
233
+