Spaces:
Sleeping
Sleeping
Update angle_detection_app.py
Browse files- angle_detection_app.py +24 -32
angle_detection_app.py
CHANGED
|
@@ -78,6 +78,9 @@ def process_image(
|
|
| 78 |
"""
|
| 79 |
Process the image and return the visualization and angle measurements.
|
| 80 |
"""
|
|
|
|
|
|
|
|
|
|
| 81 |
if isinstance(image, dict):
|
| 82 |
image = image['image']
|
| 83 |
if isinstance(image, str):
|
|
@@ -109,39 +112,28 @@ def process_image(
|
|
| 109 |
return result_img, measurements
|
| 110 |
|
| 111 |
def create_gradio_interface():
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
with gr.Column():
|
| 133 |
-
output_image = gr.Image(label="Result")
|
| 134 |
-
output_text = gr.Textbox(label="Measurements", lines=10)
|
| 135 |
-
|
| 136 |
-
process_btn.click(
|
| 137 |
-
fn=process_image,
|
| 138 |
-
inputs=[input_image, blur_kernel_size, canny_threshold1, canny_threshold2, dilation_kernel_size,
|
| 139 |
-
hough_threshold, min_line_length, max_line_gap, bend_threshold],
|
| 140 |
-
outputs=[output_image, output_text]
|
| 141 |
-
)
|
| 142 |
-
|
| 143 |
return interface
|
| 144 |
|
| 145 |
if __name__ == "__main__":
|
| 146 |
interface = create_gradio_interface()
|
| 147 |
-
interface.launch(share=
|
|
|
|
| 78 |
"""
|
| 79 |
Process the image and return the visualization and angle measurements.
|
| 80 |
"""
|
| 81 |
+
if image is None:
|
| 82 |
+
return None, "Please upload an image."
|
| 83 |
+
|
| 84 |
if isinstance(image, dict):
|
| 85 |
image = image['image']
|
| 86 |
if isinstance(image, str):
|
|
|
|
| 112 |
return result_img, measurements
|
| 113 |
|
| 114 |
def create_gradio_interface():
|
| 115 |
+
interface = gr.Interface(
|
| 116 |
+
fn=process_image,
|
| 117 |
+
inputs=[
|
| 118 |
+
gr.Image(label="Input Image", type="numpy"),
|
| 119 |
+
gr.Slider(minimum=3, maximum=15, step=2, value=7, label="Blur Kernel Size"),
|
| 120 |
+
gr.Slider(minimum=0, maximum=100, step=10, value=30, label="Canny Threshold 1"),
|
| 121 |
+
gr.Slider(minimum=100, maximum=300, step=10, value=150, label="Canny Threshold 2"),
|
| 122 |
+
gr.Slider(minimum=1, maximum=5, step=1, value=2, label="Dilation Kernel Size"),
|
| 123 |
+
gr.Slider(minimum=10, maximum=100, step=10, value=50, label="Hough Threshold"),
|
| 124 |
+
gr.Slider(minimum=5, maximum=50, step=5, value=10, label="Minimum Line Length"),
|
| 125 |
+
gr.Slider(minimum=10, maximum=100, step=10, value=60, label="Maximum Line Gap"),
|
| 126 |
+
gr.Slider(minimum=5, maximum=30, step=5, value=15, label="Bend Threshold")
|
| 127 |
+
],
|
| 128 |
+
outputs=[
|
| 129 |
+
gr.Image(label="Result"),
|
| 130 |
+
gr.Textbox(label="Measurements", lines=10)
|
| 131 |
+
],
|
| 132 |
+
title="Angle Detection App",
|
| 133 |
+
description="Upload an image to detect bends and measure angles. Adjust parameters as needed."
|
| 134 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
return interface
|
| 136 |
|
| 137 |
if __name__ == "__main__":
|
| 138 |
interface = create_gradio_interface()
|
| 139 |
+
interface.launch(share=True)
|