ezamorag commited on
Commit
54326c4
·
1 Parent(s): a1ae682

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -23
app.py CHANGED
@@ -41,30 +41,13 @@ def send2api(input_img, api_url):
41
  print(str(e))
42
  return response
43
 
44
- def display_detectionsandcountings_detclasim(img_array, detections, c_cnames, c_scinames, coverage, prob_th=0, cth = 0):
45
- img = Image.fromarray(img_array)
46
- img1 = ImageDraw.Draw(img)
47
- h, w = img.size
48
- ratio = h/4000
49
-
50
- for (box, _, y_prob, y_class, sciname) in detections:
51
- y_prob = float(y_prob)
52
- if y_prob > prob_th:
53
- img1.rectangle(box, outline='red', width=int(20*ratio))
54
- img1.text(box[:2], y_class+str(round(y_prob,3)), fill='white')
55
-
56
  countings_list = list(c_scinames.items())
57
  countings_list.sort(key = lambda x: x[1], reverse=True)
58
- yi=int(20*ratio)
59
  total = 0
60
- for (y_class,c) in countings_list:
61
- if c > cth:
62
- img1.text((int(50*ratio), yi), "# {} = {}".format(y_class, c), fill='red')
63
- yi += int(100*ratio)
64
- total += c
65
- yi += int(100*ratio)
66
- img1.text((int(50*ratio), yi), "# {} = {}".format('total', total), fill='red')
67
-
68
  text = f'coverage = {coverage}'+'\n\n'
69
  text += 'Countings by scientific name:\n'
70
  countings_list = list(c_scinames.items())
@@ -80,7 +63,7 @@ def display_detectionsandcountings_detclasim(img_array, detections, c_cnames, c_
80
  text += f'{key} = {value}'+'\n'
81
  text += '\n'
82
  text += f'total = {total}'+'\n'
83
- return img, text
84
 
85
  def displaytext_yolocounter(countings, coverage):
86
  countings_list = list(countings.items())
@@ -130,7 +113,9 @@ def testing_countingid(input_img):
130
  c_scinames = response['countings_scinames']
131
  coverage = response['coverage']
132
  detections = response['detections']
133
- img, text = display_detectionsandcountings_detclasim(input_img, detections, c_cnames, c_scinames, coverage, prob_th=0, cth = 0)
 
 
134
  return img, text
135
 
136
  def testing_yolocounter(input_img):
 
41
  print(str(e))
42
  return response
43
 
44
+ def displaytext_detclasim(c_cnames, c_scinames, coverage):
 
 
 
 
 
 
 
 
 
 
 
45
  countings_list = list(c_scinames.items())
46
  countings_list.sort(key = lambda x: x[1], reverse=True)
 
47
  total = 0
48
+ for (_,c) in countings_list:
49
+ total += c
50
+
 
 
 
 
 
51
  text = f'coverage = {coverage}'+'\n\n'
52
  text += 'Countings by scientific name:\n'
53
  countings_list = list(c_scinames.items())
 
63
  text += f'{key} = {value}'+'\n'
64
  text += '\n'
65
  text += f'total = {total}'+'\n'
66
+ return text
67
 
68
  def displaytext_yolocounter(countings, coverage):
69
  countings_list = list(countings.items())
 
113
  c_scinames = response['countings_scinames']
114
  coverage = response['coverage']
115
  detections = response['detections']
116
+ img_out = response['img_out']
117
+ img = Image.open(BytesIO(base64.b64decode(img_out)))
118
+ _, text = displaytext_detclasim(c_cnames, c_scinames, coverage)
119
  return img, text
120
 
121
  def testing_yolocounter(input_img):