umairrrkhan commited on
Commit
831fb22
·
verified ·
1 Parent(s): 34d77cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
app.py CHANGED
@@ -1,29 +1,28 @@
1
- import cv2
2
  import gradio as gr
 
3
  import numpy as np
4
 
5
- def process_frame():
6
- cap = cv2.VideoCapture(0)
7
- ret, frame = cap.read()
 
8
 
9
- if not ret:
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
- iface = gr.Interface(
21
- fn=process_frame,
22
- inputs=[],
23
- outputs="image",
24
- live=True,
25
  title="Real-Time Edge Detection",
26
- description="This application captures frames from the webcam and applies edge detection."
27
  )
28
 
29
- iface.launch()
 
 
 
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()