Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -185,14 +185,14 @@ class VideoTransformer(VideoTransformerBase):
|
|
| 185 |
def __init__(self):
|
| 186 |
self.snapshots = [] # 存储捕获的快照
|
| 187 |
self.last_capture_time = time.time() # 上次捕获时间
|
| 188 |
-
self.capture_interval =
|
| 189 |
|
| 190 |
def transform(self, frame):
|
| 191 |
"""从摄像头流捕获单帧图像,并转换为 PIL Image。"""
|
| 192 |
img = frame.to_ndarray(format="bgr24")
|
| 193 |
current_time = time.time()
|
| 194 |
-
# 每隔 capture_interval 秒捕获一张快照,直到捕获
|
| 195 |
-
if current_time - self.last_capture_time >= self.capture_interval and len(self.snapshots) <
|
| 196 |
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 197 |
self.snapshots.append(Image.fromarray(img_rgb))
|
| 198 |
self.last_capture_time = current_time
|
|
@@ -312,7 +312,7 @@ def photo_detection_page():
|
|
| 312 |
|
| 313 |
def real_time_detection_page():
|
| 314 |
st.title("实时视频检测")
|
| 315 |
-
st.write("程序在一分钟内捕获
|
| 316 |
|
| 317 |
# 创建用于显示进度文字和进度条的占位容器
|
| 318 |
capture_text_placeholder = st.empty()
|
|
@@ -328,7 +328,7 @@ def real_time_detection_page():
|
|
| 328 |
image_placeholder = st.empty()
|
| 329 |
audio_placeholder = st.empty()
|
| 330 |
|
| 331 |
-
capture_target =
|
| 332 |
|
| 333 |
if ctx.video_transformer is not None:
|
| 334 |
classification_result_placeholder = st.empty()
|
|
@@ -402,7 +402,7 @@ def real_time_detection_page():
|
|
| 402 |
classification_text_placeholder.text("分类进度: 分类完成!")
|
| 403 |
classification_progress.progress(100)
|
| 404 |
|
| 405 |
-
time.sleep(
|
| 406 |
classification_progress_placeholder.empty()
|
| 407 |
classification_text_placeholder.empty()
|
| 408 |
capture_text_placeholder.empty()
|
|
|
|
| 185 |
def __init__(self):
|
| 186 |
self.snapshots = [] # 存储捕获的快照
|
| 187 |
self.last_capture_time = time.time() # 上次捕获时间
|
| 188 |
+
self.capture_interval = 1 # 每0.5秒捕获一张快照
|
| 189 |
|
| 190 |
def transform(self, frame):
|
| 191 |
"""从摄像头流捕获单帧图像,并转换为 PIL Image。"""
|
| 192 |
img = frame.to_ndarray(format="bgr24")
|
| 193 |
current_time = time.time()
|
| 194 |
+
# 每隔 capture_interval 秒捕获一张快照,直到捕获5张
|
| 195 |
+
if current_time - self.last_capture_time >= self.capture_interval and len(self.snapshots) < 5:
|
| 196 |
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 197 |
self.snapshots.append(Image.fromarray(img_rgb))
|
| 198 |
self.last_capture_time = current_time
|
|
|
|
| 312 |
|
| 313 |
def real_time_detection_page():
|
| 314 |
st.title("实时视频检测")
|
| 315 |
+
st.write("程序在一分钟内捕获5张快照进行图片分类,首先判定是否吸烟。若检测到吸烟的快照超过2次,则展示年龄与性别分类结果。")
|
| 316 |
|
| 317 |
# 创建用于显示进度文字和进度条的占位容器
|
| 318 |
capture_text_placeholder = st.empty()
|
|
|
|
| 328 |
image_placeholder = st.empty()
|
| 329 |
audio_placeholder = st.empty()
|
| 330 |
|
| 331 |
+
capture_target = 5
|
| 332 |
|
| 333 |
if ctx.video_transformer is not None:
|
| 334 |
classification_result_placeholder = st.empty()
|
|
|
|
| 402 |
classification_text_placeholder.text("分类进度: 分类完成!")
|
| 403 |
classification_progress.progress(100)
|
| 404 |
|
| 405 |
+
time.sleep(5)
|
| 406 |
classification_progress_placeholder.empty()
|
| 407 |
classification_text_placeholder.empty()
|
| 408 |
capture_text_placeholder.empty()
|