TungDuong commited on
Commit
1bf80f3
·
verified ·
1 Parent(s): 06142a4

adding function to print text to screen

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -28,17 +28,33 @@ def pipeline(image):
28
 
29
  # Filter low conf boxes
30
  filter_predictions = []
 
 
31
  for bbox, cls, conf, text, encoded_text in predictions:
32
  if conf > 0.7:
33
  filter_predictions.append([bbox, cls, conf, text, encoded_text])
34
 
 
 
 
 
 
 
 
 
 
 
 
35
  image = visualize_image(image, filter_predictions)
36
- return image
37
 
38
  demo = gr.Interface(
39
  fn=pipeline,
40
  inputs=gr.Image(type="pil", label="Input Image"),
41
- outputs="image",
 
 
 
42
  title="Scene Text Recognization",
43
  description="Recognize text in scene images"
44
  )
 
28
 
29
  # Filter low conf boxes
30
  filter_predictions = []
31
+ dict_predictions = {}
32
+ num_textbox = 1
33
  for bbox, cls, conf, text, encoded_text in predictions:
34
  if conf > 0.7:
35
  filter_predictions.append([bbox, cls, conf, text, encoded_text])
36
 
37
+ xmin, ymin, xmax, ymax = bbox
38
+ xmin, ymin, xmax, ymax = int(xmin), int(ymin), int(xmax), int(ymax)
39
+ dict_predictions.update({
40
+ f"textbox {num_textbox}":{
41
+ "bounding box": str([xmin, ymin, xmax, ymax]),
42
+ "conf": np.round(conf, 2),
43
+ "text": text
44
+ }
45
+ })
46
+ num_textbox += 1
47
+
48
  image = visualize_image(image, filter_predictions)
49
+ return image, json.dumps(dict_predictions, indent=5)
50
 
51
  demo = gr.Interface(
52
  fn=pipeline,
53
  inputs=gr.Image(type="pil", label="Input Image"),
54
+ outputs=[
55
+ gr.Image(type="pil", label="Output Image"),
56
+ gr.Textbox(type="text", label="Recognized Text")
57
+ ],
58
  title="Scene Text Recognization",
59
  description="Recognize text in scene images"
60
  )