@@ -89,12 +89,16 @@ def __init__(
89
89
confidence : float = 0.5 ,
90
90
# https://stackoverflow.com/a/77479465
91
91
classes : list [int ] = None ,
92
+ target : int = 0 , # 0: 'person'
92
93
):
93
94
# model_name: https://docs.ultralytics.com/models/yolov8/#supported-tasks-and-modes
94
95
self .model = YOLO (model_name )
96
+ # label names, 0: 'person', 1: 'bicycle', 2: 'car'
97
+ # print(self.model.names)
95
98
self .confidence = confidence
96
99
self .classes = classes
97
- self .num_of_persons = 0
100
+ self .num = 0
101
+ self .target = target
98
102
99
103
def process (
100
104
self ,
@@ -105,7 +109,7 @@ def process(
105
109
conf = self .confidence ,
106
110
classes = self .classes ,
107
111
)
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 ])
109
113
output_img = results [0 ].plot (
110
114
labels = True ,
111
115
conf = True ,
@@ -117,7 +121,7 @@ def process(
117
121
118
122
def get_states (self ):
119
123
return {
120
- "num_of_persons " : self .num_of_persons ,
124
+ "num " : self .num ,
121
125
}
122
126
123
127
@@ -194,10 +198,10 @@ def get_processor(processor_type: ProcessorType) -> Processor:
194
198
st .text (f"processor: { processor_type .value } " )
195
199
196
200
start_button = st .button ("Start" )
197
- stop = st .button ("Stop" )
201
+ stop_button = st .button ("Stop" )
198
202
199
203
image_loc = st .empty ()
200
- message_loc = st .empty ()
204
+ states_loc = st .empty ()
201
205
processor = get_processor (processor_type )
202
206
203
207
if start_button :
@@ -215,14 +219,14 @@ def get_processor(processor_type: ProcessorType) -> Processor:
215
219
)
216
220
217
221
states = processor .get_states ()
218
- message_loc . info ( f" states: { states } " )
222
+ states_loc . write ( states )
219
223
220
224
image_loc .image (
221
225
image = processed_frame ,
222
226
use_column_width = True ,
223
227
)
224
228
225
- if stop :
229
+ if stop_button :
226
230
break
227
231
228
232
capture .release ()
0 commit comments