File size: 927 Bytes
f70c427
 
 
 
 
 
 
 
 
 
 
 
30d469c
f70c427
30d469c
f70c427
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv2 as cv
import gradio as gr
from dexined import Dexined
from huggingface_hub import hf_hub_download

# Download ONNX model from Hugging Face
model_path = hf_hub_download(repo_id="opencv/edge_detection_dexined", filename="edge_detection_dexined_2024sep.onnx")

# Initialize model
model = Dexined(modelPath=model_path)

def detect_edges(input_image):
    input_image = cv.cvtColor(input_image, cv.COLOR_RGB2BGR)
    result = model.infer(input_image)
    result = cv.cvtColor(result, cv.COLOR_BGR2RGB)
    return result

# Gradio UI
demo = gr.Interface(
    fn=detect_edges,
    inputs=gr.Image(type="numpy", label="Upload Image"),
    outputs=gr.Image(type="numpy", label="Output"),
    title="Edge Detection DexiNed (OpenCV DNN)",
    allow_flagging="never",
    description="Upload an image to detect edges using OpenCV's ONNX-based edge detection using DexiNed model."
)

if __name__ == "__main__":
    demo.launch()