Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -82,36 +82,16 @@ def display_detectionsandcountings_detclasim(img_array, detections, c_cnames, c_
|
|
82 |
text += f'total = {total}'+'\n'
|
83 |
return img, text
|
84 |
|
85 |
-
def
|
86 |
-
img = Image.fromarray(img_array)
|
87 |
-
img1 = ImageDraw.Draw(img)
|
88 |
-
h, w = img.size
|
89 |
-
ratio = h/4000
|
90 |
-
|
91 |
-
for (box, _, y_prob, y_class) in detections:
|
92 |
-
y_prob = float(y_prob)
|
93 |
-
if y_prob > prob_th:
|
94 |
-
img1.rectangle(box, outline='red', width=int(20*ratio))
|
95 |
-
img1.text(box[:2], y_class+str(round(y_prob,3)), fill='white')
|
96 |
-
|
97 |
countings_list = list(countings.items())
|
98 |
countings_list.sort(key = lambda x: x[1], reverse=True)
|
99 |
-
yi=int(20*ratio)
|
100 |
-
total = 0
|
101 |
-
for (y_class,c) in countings_list:
|
102 |
-
if c > cth:
|
103 |
-
img1.text((int(50*ratio), yi), "# {} = {}".format(y_class, c), fill='red')
|
104 |
-
yi += int(100*ratio)
|
105 |
-
total += c
|
106 |
-
yi += int(100*ratio)
|
107 |
-
img1.text((int(50*ratio), yi), "# {} = {}".format('total', total), fill='red')
|
108 |
|
109 |
text = f'coverage = {coverage}'+'\n\n'
|
110 |
for key,value in countings_list:
|
111 |
text += f'{key} = {value}'+'\n'
|
112 |
text += '\n'
|
113 |
text += f'total = {total}'+'\n'
|
114 |
-
return
|
115 |
|
116 |
def display_detectionsandcountings_directcounter(img_array, countings, prob_th=0, cth = 0):
|
117 |
img = Image.fromarray(img_array)
|
@@ -158,7 +138,7 @@ def testing_yolocounter(input_img):
|
|
158 |
detections = response['detections']
|
159 |
img_out = response['img_out']
|
160 |
img = Image.open(BytesIO(base64.b64decode(img_out)))
|
161 |
-
|
162 |
return img, text
|
163 |
|
164 |
def testing_directcounter(input_img):
|
|
|
82 |
text += f'total = {total}'+'\n'
|
83 |
return img, text
|
84 |
|
85 |
+
def displaytext_yolocounter(countings, coverage):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
countings_list = list(countings.items())
|
87 |
countings_list.sort(key = lambda x: x[1], reverse=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
text = f'coverage = {coverage}'+'\n\n'
|
90 |
for key,value in countings_list:
|
91 |
text += f'{key} = {value}'+'\n'
|
92 |
text += '\n'
|
93 |
text += f'total = {total}'+'\n'
|
94 |
+
return text
|
95 |
|
96 |
def display_detectionsandcountings_directcounter(img_array, countings, prob_th=0, cth = 0):
|
97 |
img = Image.fromarray(img_array)
|
|
|
138 |
detections = response['detections']
|
139 |
img_out = response['img_out']
|
140 |
img = Image.open(BytesIO(base64.b64decode(img_out)))
|
141 |
+
text = displaytext_yolocounter(countings, coverage)
|
142 |
return img, text
|
143 |
|
144 |
def testing_directcounter(input_img):
|