Spaces:
Running
Running
File size: 1,341 Bytes
acad9f5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
from utils import (
sobel_edge_detection,
canny_edge_detection,
hough_lines,
laplacian_edge_detection,
contours_detection,
prewitt_edge_detection,
gradient_magnitude,
corner_detection,
)
import cv2
import numpy as np
def predict_image(algorithm, image):
# Apply edge detection (e.g., Canny)
edges = cv2.Canny(image, 50, 150, apertureSize=3)
# Apply Hough Line Transform
lines = cv2.HoughLines(edges, 1, np.pi / 180, threshold=100)
# Draw lines on the original image
for line in lines:
rho, theta = line[0]
a = np.cos(theta)
b = np.sin(theta)
x0 = a * rho
y0 = b * rho
x1 = int(x0 + 1000 * (-b))
y1 = int(y0 + 1000 * (a))
x2 = int(x0 - 1000 * (-b))
y2 = int(y0 - 1000 * (a))
cv2.line(image, (x1, y1), (x2, y2), (0, 0, 255), 2)
return edges
GrImage = gr.Image()
GrDropdown = gr.Dropdown(
[
"Sobel Edge Detection",
"Canny Edge Detection",
"Hough Lines",
"Laplacian Edge Detection",
"Contours Detection",
"Prewitt Edge Detection",
"Gradient Magnitude",
"Corner Detection",
]
)
GrOutput = gr.Image()
iface = gr.Interface(fn=predict_image, inputs=[ GrDropdown,GrImage], outputs=GrOutput)
iface.launch()
|