zdou0830 commited on
Commit
b39562c
1 Parent(s): 7f2ed69
Files changed (1) hide show
  1. app.py +3 -21
app.py CHANGED
@@ -59,29 +59,11 @@ athetics_params = {
59
  "text_offset_original": 8, # distance between text and box
60
  }
61
 
62
- def resize_image_by_height(image, new_height=500):
63
- import cv2
64
- height, width, _ = image.shape
65
- aspect_ratio = width / height
66
- new_width = int(new_height * aspect_ratio)
67
- resized_image = cv2.resize(image, (new_width, new_height))
68
- return resized_image
69
-
70
- def resize_image_by_width(image, new_width=500):
71
- import cv2
72
- height, width, _ = image.shape
73
- aspect_ratio = height / width
74
- new_height = int(new_width * aspect_ratio)
75
- resized_image = cv2.resize(image, (new_width, new_height))
76
- return resized_image
77
-
78
  def predict(image, text, ground_tokens=""):
79
- #image = resize_image_by_width(image)
80
- print(image.shape)
81
- max_len = max(image.shape)
82
  import math
83
- athetics_params["text_size"] = math.ceil(max_len/1000)
84
- athetics_params["text_pixel"] = math.ceil(max_len/1000*3)
85
  ground_tokens = None if ground_tokens.strip() == "" else ground_tokens.strip().split(";")
86
  result, _ = glip_demo.run_on_web_image(deepcopy(image[:, :, [2, 1, 0]]), text, 0.5, ground_tokens, **athetics_params)
87
  fiber_result, _ = fiber_demo.run_on_web_image(deepcopy(image[:, :, [2, 1, 0]]), text, 0.5, ground_tokens, **athetics_params)
 
59
  "text_offset_original": 8, # distance between text and box
60
  }
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  def predict(image, text, ground_tokens=""):
63
+ img_len = min(image.shape[:2])
 
 
64
  import math
65
+ athetics_params["text_size"] = math.ceil(img_len/1000)
66
+ athetics_params["text_pixel"] = math.ceil(img_len/1000*3)
67
  ground_tokens = None if ground_tokens.strip() == "" else ground_tokens.strip().split(";")
68
  result, _ = glip_demo.run_on_web_image(deepcopy(image[:, :, [2, 1, 0]]), text, 0.5, ground_tokens, **athetics_params)
69
  fiber_result, _ = fiber_demo.run_on_web_image(deepcopy(image[:, :, [2, 1, 0]]), text, 0.5, ground_tokens, **athetics_params)