added detection counts
Browse files- .streamlit/config.toml +6 -0
- app.py +22 -5
.streamlit/config.toml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
primaryColor="#F63366"
|
3 |
+
backgroundColor="#FFFFFF"
|
4 |
+
secondaryBackgroundColor="#F0F2F6"
|
5 |
+
textColor="#262730"
|
6 |
+
font="sans serif"
|
app.py
CHANGED
@@ -37,6 +37,8 @@ def run_inference(model, img_paths):
|
|
37 |
# helper function to process result and return image with bbox overlays
|
38 |
def process_inference_result(result, class_colors):
|
39 |
|
|
|
|
|
40 |
# extract result objects
|
41 |
img = result.orig_img
|
42 |
dh, dw, _ = img.shape
|
@@ -55,10 +57,25 @@ def process_inference_result(result, class_colors):
|
|
55 |
voc_y1 = voc_box[1]
|
56 |
voc_x2 = voc_box[2]
|
57 |
voc_y2 = voc_box[3]
|
|
|
58 |
cv2.rectangle(img, (voc_x1, voc_y1), (voc_x2, voc_y2), class_colors[labels[i]], 2)
|
59 |
-
cv2.putText(img,
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
def run_process_show(img_path):
|
64 |
results = model(img_path)
|
@@ -107,7 +124,7 @@ big_img = st.image(img)
|
|
107 |
status.write("Running OneEye detector...")
|
108 |
|
109 |
# process image through detector
|
110 |
-
img2 = run_process_show(img)
|
111 |
big_img.image(img2)
|
112 |
|
113 |
-
status.write(
|
|
|
37 |
# helper function to process result and return image with bbox overlays
|
38 |
def process_inference_result(result, class_colors):
|
39 |
|
40 |
+
# setup label counts
|
41 |
+
label_counts = {'class': [], 'count': []}
|
42 |
# extract result objects
|
43 |
img = result.orig_img
|
44 |
dh, dw, _ = img.shape
|
|
|
57 |
voc_y1 = voc_box[1]
|
58 |
voc_x2 = voc_box[2]
|
59 |
voc_y2 = voc_box[3]
|
60 |
+
class_name = aircraft_lookup[classes[labels[i]]]
|
61 |
cv2.rectangle(img, (voc_x1, voc_y1), (voc_x2, voc_y2), class_colors[labels[i]], 2)
|
62 |
+
cv2.putText(img, class_name + ' ' + str(round(conf[i], 2)), (voc_x1, voc_y1-5), cv2.FONT_HERSHEY_SIMPLEX, 1, class_colors[labels[i]], 2)
|
63 |
+
if class_name not in label_counts['class']:
|
64 |
+
label_counts['class'].append(class_name)
|
65 |
+
label_counts['count'].append(1)
|
66 |
+
else:
|
67 |
+
label_counts['count'][label_counts['class'].index(class_name)] += 1
|
68 |
+
|
69 |
+
return img, label_counts
|
70 |
+
|
71 |
+
def get_detection_count_display(classes):
|
72 |
+
if(len(classes)):
|
73 |
+
disp_str = "[Aircraft detected] "
|
74 |
+
for class_name, count in enumerate(classes):
|
75 |
+
disp_str += class_name + ": " + str(count) + " "
|
76 |
+
else:
|
77 |
+
disp_str = "[No aircraft detected]"
|
78 |
+
return disp_str
|
79 |
|
80 |
def run_process_show(img_path):
|
81 |
results = model(img_path)
|
|
|
124 |
status.write("Running OneEye detector...")
|
125 |
|
126 |
# process image through detector
|
127 |
+
img2, detection_labels = run_process_show(img)
|
128 |
big_img.image(img2)
|
129 |
|
130 |
+
status.write(get_detection_count_display(detection_labels))
|