Add example image functionality
Browse files- app.py +22 -0
- example/girl.jpeg +0 -0
- example/sea.jpeg +0 -0
app.py
CHANGED
|
@@ -22,6 +22,12 @@ def segmentation_interface(image, spatial_radius, color_radius):
|
|
| 22 |
segmented = segment_image(image, spatial_radius, color_radius)
|
| 23 |
return cv2.cvtColor(segmented, cv2.COLOR_BGR2RGB)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
with gr.Blocks() as demo:
|
| 26 |
gr.Markdown("### OpenCV 基本影像處理工具")
|
| 27 |
|
|
@@ -36,6 +42,14 @@ with gr.Blocks() as demo:
|
|
| 36 |
edge_button.click(edge_detection_interface,
|
| 37 |
inputs=[input_image, threshold1_slider, threshold2_slider],
|
| 38 |
outputs=output_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
with gr.Tab("影像分割"):
|
| 41 |
with gr.Row():
|
|
@@ -48,6 +62,14 @@ with gr.Blocks() as demo:
|
|
| 48 |
segment_button.click(segmentation_interface,
|
| 49 |
inputs=[input_image_seg, spatial_slider, color_slider],
|
| 50 |
outputs=output_image_seg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# 啟動介面
|
| 53 |
if __name__ == "__main__":
|
|
|
|
| 22 |
segmented = segment_image(image, spatial_radius, color_radius)
|
| 23 |
return cv2.cvtColor(segmented, cv2.COLOR_BGR2RGB)
|
| 24 |
|
| 25 |
+
# 範例影像的路徑
|
| 26 |
+
example_images = [
|
| 27 |
+
"examples/girl.jpg",
|
| 28 |
+
"examples/sea.jpg"
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
gr.Markdown("### OpenCV 基本影像處理工具")
|
| 33 |
|
|
|
|
| 42 |
edge_button.click(edge_detection_interface,
|
| 43 |
inputs=[input_image, threshold1_slider, threshold2_slider],
|
| 44 |
outputs=output_image)
|
| 45 |
+
# 範例影像按鈕
|
| 46 |
+
gr.Examples(
|
| 47 |
+
examples=example_images,
|
| 48 |
+
inputs=input_image,
|
| 49 |
+
outputs=output_image,
|
| 50 |
+
fn=lambda x: x,
|
| 51 |
+
label="範例影像"
|
| 52 |
+
)
|
| 53 |
|
| 54 |
with gr.Tab("影像分割"):
|
| 55 |
with gr.Row():
|
|
|
|
| 62 |
segment_button.click(segmentation_interface,
|
| 63 |
inputs=[input_image_seg, spatial_slider, color_slider],
|
| 64 |
outputs=output_image_seg)
|
| 65 |
+
# 範例影像按鈕
|
| 66 |
+
gr.Examples(
|
| 67 |
+
examples=example_images,
|
| 68 |
+
inputs=input_image,
|
| 69 |
+
outputs=output_image,
|
| 70 |
+
fn=lambda x: x,
|
| 71 |
+
label="範例影像"
|
| 72 |
+
)
|
| 73 |
|
| 74 |
# 啟動介面
|
| 75 |
if __name__ == "__main__":
|
example/girl.jpeg
ADDED
|
example/sea.jpeg
ADDED
|