Skip to content

Commit 643aec3

Browse files
committed
cosmetic changes
1 parent 4e693b4 commit 643aec3

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

apps/99_streamlit_examples/pages/12_Video_processing.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,16 @@ def __init__(
8989
confidence: float = 0.5,
9090
# https://stackoverflow.com/a/77479465
9191
classes: list[int] = None,
92+
target: int = 0, # 0: 'person'
9293
):
9394
# model_name: https://docs.ultralytics.com/models/yolov8/#supported-tasks-and-modes
9495
self.model = YOLO(model_name)
96+
# label names, 0: 'person', 1: 'bicycle', 2: 'car'
97+
# print(self.model.names)
9598
self.confidence = confidence
9699
self.classes = classes
97-
self.num_of_persons = 0
100+
self.num = 0
101+
self.target = target
98102

99103
def process(
100104
self,
@@ -105,7 +109,7 @@ def process(
105109
conf=self.confidence,
106110
classes=self.classes,
107111
)
108-
self.num_of_persons = len([x for x in results[0].boxes.cls if x == 0])
112+
self.num = len([x for x in results[0].boxes.cls if x == self.target])
109113
output_img = results[0].plot(
110114
labels=True,
111115
conf=True,
@@ -117,7 +121,7 @@ def process(
117121

118122
def get_states(self):
119123
return {
120-
"num_of_persons": self.num_of_persons,
124+
"num": self.num,
121125
}
122126

123127

@@ -194,10 +198,10 @@ def get_processor(processor_type: ProcessorType) -> Processor:
194198
st.text(f"processor: {processor_type.value}")
195199

196200
start_button = st.button("Start")
197-
stop = st.button("Stop")
201+
stop_button = st.button("Stop")
198202

199203
image_loc = st.empty()
200-
message_loc = st.empty()
204+
states_loc = st.empty()
201205
processor = get_processor(processor_type)
202206

203207
if start_button:
@@ -215,14 +219,14 @@ def get_processor(processor_type: ProcessorType) -> Processor:
215219
)
216220

217221
states = processor.get_states()
218-
message_loc.info(f"states: {states}")
222+
states_loc.write(states)
219223

220224
image_loc.image(
221225
image=processed_frame,
222226
use_column_width=True,
223227
)
224228

225-
if stop:
229+
if stop_button:
226230
break
227231

228232
capture.release()

0 commit comments

Comments
 (0)