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()