Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,28 @@
|
|
1 |
-
import cv2
|
2 |
import gradio as gr
|
|
|
3 |
import numpy as np
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
8 |
|
9 |
-
|
10 |
-
cap.release()
|
11 |
-
return np.zeros((512, 512, 3), dtype=np.uint8)
|
12 |
-
|
13 |
-
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
14 |
edges = cv2.Canny(gray, 100, 200)
|
|
|
|
|
15 |
edges_bgr = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
|
16 |
-
|
17 |
-
cap.release()
|
18 |
return edges_bgr
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
title="Real-Time Edge Detection",
|
26 |
-
description="
|
27 |
)
|
28 |
|
29 |
-
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import cv2
|
3 |
import numpy as np
|
4 |
|
5 |
+
# Function to process uploaded images
|
6 |
+
def process_image(image):
|
7 |
+
# Convert image to grayscale
|
8 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
9 |
|
10 |
+
# Apply Canny edge detection
|
|
|
|
|
|
|
|
|
11 |
edges = cv2.Canny(gray, 100, 200)
|
12 |
+
|
13 |
+
# Convert edges back to 3-channel image for display
|
14 |
edges_bgr = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
|
15 |
+
|
|
|
16 |
return edges_bgr
|
17 |
|
18 |
+
# Gradio Interface
|
19 |
+
interface = gr.Interface(
|
20 |
+
fn=process_image,
|
21 |
+
inputs=gr.Image(type="numpy", label="Upload an Image"),
|
22 |
+
outputs=gr.Image(type="numpy", label="Edges Detected"),
|
23 |
title="Real-Time Edge Detection",
|
24 |
+
description="Upload an image to detect edges using Canny Edge Detection."
|
25 |
)
|
26 |
|
27 |
+
# Launch the app
|
28 |
+
interface.launch()
|