@@ -16,7 +16,7 @@ class ProcessorType(Enum):
16
16
YOLOV8 = "yolov8"
17
17
18
18
19
- class InputSource (Enum ):
19
+ class InputSourceType (Enum ):
20
20
CAMERA = "camera"
21
21
FILE = "file"
22
22
@@ -28,6 +28,9 @@ def process(
28
28
) -> cv2 .UMat :
29
29
raise NotImplementedError
30
30
31
+ def get_states (self ) -> dict :
32
+ return {}
33
+
31
34
32
35
class BlurProcessor (Processor ):
33
36
def process (
@@ -91,6 +94,7 @@ def __init__(
91
94
self .model = YOLO (model_name )
92
95
self .confidence = confidence
93
96
self .classes = classes
97
+ self .num_of_persons = 0
94
98
95
99
def process (
96
100
self ,
@@ -101,6 +105,7 @@ def process(
101
105
conf = self .confidence ,
102
106
classes = self .classes ,
103
107
)
108
+ self .num_of_persons = len ([x for x in results [0 ].boxes .cls if x == 0 ])
104
109
output_img = results [0 ].plot (
105
110
labels = True ,
106
111
conf = True ,
@@ -110,6 +115,11 @@ def process(
110
115
code = cv2 .COLOR_BGR2RGB ,
111
116
)
112
117
118
+ def get_states (self ):
119
+ return {
120
+ "num_of_persons" : self .num_of_persons ,
121
+ }
122
+
113
123
114
124
def get_processor (processor_type : ProcessorType ) -> Processor :
115
125
if processor_type == ProcessorType .BLUR :
@@ -127,21 +137,21 @@ def get_processor(processor_type: ProcessorType) -> Processor:
127
137
with st .sidebar :
128
138
tab_input , tab_mode = st .tabs (
129
139
[
130
- "input " ,
131
- "mode " ,
140
+ "source " ,
141
+ "processor " ,
132
142
]
133
143
)
134
144
with tab_input :
135
- source = st .radio (
145
+ input_source_type = st .radio (
136
146
label = "input source" ,
137
147
options = [
138
- InputSource .FILE ,
139
- InputSource .CAMERA ,
148
+ InputSourceType .FILE ,
149
+ InputSourceType .CAMERA ,
140
150
],
141
151
index = 0 ,
142
152
format_func = lambda x : x .value ,
143
153
)
144
- if source == InputSource .FILE :
154
+ if input_source_type == InputSourceType .FILE :
145
155
file = st .file_uploader (
146
156
label = "upload video file" ,
147
157
type = [
@@ -155,7 +165,7 @@ def get_processor(processor_type: ProcessorType) -> Processor:
155
165
with open (file_path , "wb" ) as f :
156
166
f .write (file .read ())
157
167
device = file_path
158
- if source == InputSource .CAMERA :
168
+ if input_source_type == InputSourceType .CAMERA :
159
169
# device: https://docs.opencv.org/4.10.0/d8/dfe/classcv_1_1VideoCapture.html#a5d5f5dacb77bbebdcbfb341e3d4355c1
160
170
device = st .text_input (
161
171
label = "input your video/camera device" ,
@@ -180,6 +190,9 @@ def get_processor(processor_type: ProcessorType) -> Processor:
180
190
181
191
st .title ("Video processing" )
182
192
193
+ st .text (f"source: { input_source_type .value } " )
194
+ st .text (f"processor: { processor_type .value } " )
195
+
183
196
start_button = st .button ("Start" )
184
197
stop = st .button ("Stop" )
185
198
@@ -194,13 +207,16 @@ def get_processor(processor_type: ProcessorType) -> Processor:
194
207
ret , frame = capture .read ()
195
208
196
209
if not ret :
197
- message_loc . error ( "Failed to read frame " )
198
- continue
210
+ st . toast ( "End of video" , icon = "❗ " )
211
+ break
199
212
200
213
processed_frame = processor .process (
201
214
frame = frame ,
202
215
)
203
216
217
+ states = processor .get_states ()
218
+ message_loc .info (f"states: { states } " )
219
+
204
220
image_loc .image (
205
221
image = processed_frame ,
206
222
use_column_width = True ,
0 commit comments