JustinLin610 commited on
Commit
e235062
1 Parent(s): aa287a2
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -73,8 +73,9 @@ def get_images(img: str, reader: ReaderLite, **kwargs):
73
 
74
  def draw_boxes(image, bounds, color='red', width=2):
75
  draw = ImageDraw.Draw(image)
76
- for bound in bounds:
77
  p0, p1, p2, p3 = bound
 
78
  draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
79
  return image
80
 
@@ -170,7 +171,7 @@ def ocr(img):
170
  draw_boxes(out_img, box_list)
171
 
172
  ocr_result = []
173
- for box, image in zip(box_list, image_list):
174
  image = Image.fromarray(image)
175
  sample = construct_sample(task, image, cfg.task.patch_image_size)
176
  sample = utils.move_to_cuda(sample) if use_cuda else sample
@@ -178,7 +179,7 @@ def ocr(img):
178
 
179
  with torch.no_grad():
180
  result, scores = eval_step(task, generator, models, sample)
181
- ocr_result.append(result[0]['ocr'].replace(' ', ''))
182
 
183
  result = '\n'.join(ocr_result)
184
 
 
73
 
74
  def draw_boxes(image, bounds, color='red', width=2):
75
  draw = ImageDraw.Draw(image)
76
+ for i, bound in enumerate(bounds):
77
  p0, p1, p2, p3 = bound
78
+ draw.text(p0, str(i+1), fill=color)
79
  draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
80
  return image
81
 
 
171
  draw_boxes(out_img, box_list)
172
 
173
  ocr_result = []
174
+ for i, (box, image) in enumerate(zip(box_list, image_list)):
175
  image = Image.fromarray(image)
176
  sample = construct_sample(task, image, cfg.task.patch_image_size)
177
  sample = utils.move_to_cuda(sample) if use_cuda else sample
 
179
 
180
  with torch.no_grad():
181
  result, scores = eval_step(task, generator, models, sample)
182
+ ocr_result.append(str(i+1) + '\t' + result[0]['ocr'].replace(' ', ''))
183
 
184
  result = '\n'.join(ocr_result)
185