Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -53,6 +53,9 @@ def detect_webcam(camera_input, conf_threshold):
|
|
53 |
if current_model is None:
|
54 |
raise gr.Error("请先上传模型文件")
|
55 |
|
|
|
|
|
|
|
56 |
results = current_model(camera_input, conf=conf_threshold)
|
57 |
plotted = results[0].plot()
|
58 |
return plotted[:, :, ::-1] # BGR转RGB
|
@@ -82,14 +85,15 @@ with gr.Blocks() as demo:
|
|
82 |
video_button = gr.Button("执行检测")
|
83 |
|
84 |
with gr.TabItem("实时摄像头"):
|
85 |
-
webcam_input = gr.
|
86 |
-
webcam_output = gr.Image(label="检测结果"
|
87 |
webcam_conf = gr.Slider(0, 1, value=0.5, label="置信度阈值")
|
|
|
88 |
|
89 |
# 绑定事件处理
|
90 |
img_button.click(fn=detect_image, inputs=[img_input, img_conf], outputs=img_output)
|
91 |
video_button.click(fn=detect_video, inputs=[video_input, video_conf], outputs=video_output)
|
92 |
-
|
93 |
|
94 |
if __name__ == "__main__":
|
95 |
demo.launch()
|
|
|
53 |
if current_model is None:
|
54 |
raise gr.Error("请先上传模型文件")
|
55 |
|
56 |
+
if camera_input is None:
|
57 |
+
return None
|
58 |
+
|
59 |
results = current_model(camera_input, conf=conf_threshold)
|
60 |
plotted = results[0].plot()
|
61 |
return plotted[:, :, ::-1] # BGR转RGB
|
|
|
85 |
video_button = gr.Button("执行检测")
|
86 |
|
87 |
with gr.TabItem("实时摄像头"):
|
88 |
+
webcam_input = gr.Webcam(label="摄像头画面")
|
89 |
+
webcam_output = gr.Image(label="检测结果")
|
90 |
webcam_conf = gr.Slider(0, 1, value=0.5, label="置信度阈值")
|
91 |
+
webcam_button = gr.Button("开始检测")
|
92 |
|
93 |
# 绑定事件处理
|
94 |
img_button.click(fn=detect_image, inputs=[img_input, img_conf], outputs=img_output)
|
95 |
video_button.click(fn=detect_video, inputs=[video_input, video_conf], outputs=video_output)
|
96 |
+
webcam_button.click(fn=detect_webcam, inputs=[webcam_input, webcam_conf], outputs=webcam_output)
|
97 |
|
98 |
if __name__ == "__main__":
|
99 |
demo.launch()
|