Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -251,6 +251,22 @@ def process_video(video_path, iou_threshold, confidence_threshold, show_detectio
|
|
| 251 |
|
| 252 |
return frames, summary
|
| 253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
# Gradio Interface
|
| 255 |
with gr.Blocks(title="Screw Detection and Measurement") as demo:
|
| 256 |
gr.Markdown("# 🔍 Screw Detection and Measurement (YOLOv11 OBB)")
|
|
@@ -299,15 +315,15 @@ with gr.Blocks(title="Screw Detection and Measurement") as demo:
|
|
| 299 |
webcam_iou = gr.Slider(label="IoU Threshold (NMS)", minimum=0.0, maximum=1.0, value=0.7, step=0.05)
|
| 300 |
webcam_conf = gr.Slider(label="Confidence Threshold", minimum=0.0, maximum=1.0, value=0.5, step=0.05)
|
| 301 |
webcam_show_det = gr.Checkbox(label="Show Detections", value=True)
|
| 302 |
-
webcam_show_sum = gr.Checkbox(label="Show Summary", value=True)
|
| 303 |
-
settings_button = gr.Button("Update Settings")
|
| 304 |
with gr.Column():
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
|
|
|
|
|
|
| 312 |
|
| 313 |
demo.launch()
|
|
|
|
| 251 |
|
| 252 |
return frames, summary
|
| 253 |
|
| 254 |
+
def process_webcam(frame, iou_threshold, confidence_threshold, show_detections):
|
| 255 |
+
# Convert from Gradio's webcam format to OpenCV
|
| 256 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
|
| 257 |
+
|
| 258 |
+
# Process the frame (using your existing process_frame function)
|
| 259 |
+
processed_frame, detected_objects, _ = process_frame(
|
| 260 |
+
frame,
|
| 261 |
+
iou_threshold=iou_threshold,
|
| 262 |
+
confidence_threshold=confidence_threshold,
|
| 263 |
+
show_detections=show_detections
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
# Convert back to RGB for Gradio
|
| 267 |
+
processed_frame = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB)
|
| 268 |
+
return processed_frame
|
| 269 |
+
|
| 270 |
# Gradio Interface
|
| 271 |
with gr.Blocks(title="Screw Detection and Measurement") as demo:
|
| 272 |
gr.Markdown("# 🔍 Screw Detection and Measurement (YOLOv11 OBB)")
|
|
|
|
| 315 |
webcam_iou = gr.Slider(label="IoU Threshold (NMS)", minimum=0.0, maximum=1.0, value=0.7, step=0.05)
|
| 316 |
webcam_conf = gr.Slider(label="Confidence Threshold", minimum=0.0, maximum=1.0, value=0.5, step=0.05)
|
| 317 |
webcam_show_det = gr.Checkbox(label="Show Detections", value=True)
|
|
|
|
|
|
|
| 318 |
with gr.Column():
|
| 319 |
+
webcam_input = gr.Image(source="webcam", streaming=True, label="Live Camera")
|
| 320 |
+
webcam_output = gr.Image(label="Processed Output", streaming=True)
|
| 321 |
+
|
| 322 |
+
# Create live processing
|
| 323 |
+
webcam_input.change(
|
| 324 |
+
fn=process_webcam,
|
| 325 |
+
inputs=[webcam_input, webcam_iou, webcam_conf, webcam_show_det],
|
| 326 |
+
outputs=webcam_output
|
| 327 |
+
)
|
| 328 |
|
| 329 |
demo.launch()
|