yuragoithf commited on
Commit
17b3106
·
verified ·
1 Parent(s): e44b901

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -37,16 +37,21 @@ def recognize_handwritten_text(image):
37
  return Image.fromarray(processed_image), "No text detected"
38
 
39
  boxes = outputs[0]["boxes"]
 
40
  pil_image = Image.fromarray(processed_image)
41
  texts = []
42
 
43
  # Adjust box unpacking based on actual structure
44
  for box in boxes:
45
- if len(box) >= 4: # Check if box has at least 4 coordinates
46
- x_min, y_min, x_max, y_max = box[0][0], box[0][1], box[2][0], box[2][1]
47
- elif len(box) == 2: # Handle case with only 2 points (e.g., center and size)
48
- x_min, y_min = box[0][0] - box[1][0] / 2, box[0][1] - box[1][1] / 2
49
- x_max, y_max = box[0][0] + box[1][0] / 2, box[0][1] + box[1][1] / 2
 
 
 
 
50
  else:
51
  continue # Skip invalid boxes
52
 
 
37
  return Image.fromarray(processed_image), "No text detected"
38
 
39
  boxes = outputs[0]["boxes"]
40
+ print(f"Debug: Boxes structure = {boxes}") # Debug output to logs
41
  pil_image = Image.fromarray(processed_image)
42
  texts = []
43
 
44
  # Adjust box unpacking based on actual structure
45
  for box in boxes:
46
+ if len(box) == 4: # [x, y, width, height] format
47
+ x_min, y_min, width, height = box
48
+ x_max = x_min + width
49
+ y_max = y_min + height
50
+ elif len(box) == 2 and len(box[0]) == 2: # [[x, y], [width, height]] format
51
+ x_min, y_min = box[0]
52
+ width, height = box[1]
53
+ x_max = x_min + width
54
+ y_max = y_min + height
55
  else:
56
  continue # Skip invalid boxes
57