Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
mischeiwiller
commited on
Commit
•
5cdd253
1
Parent(s):
e43d011
Update app.py
Browse files
app.py
CHANGED
@@ -34,8 +34,8 @@ def sort_centroids_clockwise(centroids: np.ndarray):
|
|
34 |
|
35 |
def infer(image_input, dst_height: str, dst_width: str):
|
36 |
if isinstance(image_input, dict):
|
37 |
-
image_in = image_input[
|
38 |
-
mask_in = image_input[
|
39 |
else:
|
40 |
image_in = image_input
|
41 |
mask_in = np.zeros_like(image_in)
|
@@ -77,7 +77,7 @@ def infer(image_input, dst_height: str, dst_width: str):
|
|
77 |
|
78 |
description = """In this space you can warp an image using perspective transform with the Kornia library as seen in [this tutorial](https://kornia.github.io/tutorials/#category=Homography).
|
79 |
1. Upload an image or use the example provided
|
80 |
-
2. Set 4 points into the image
|
81 |
3. Set a desired output size (or go with the default)
|
82 |
4. Click Submit to run the demo
|
83 |
"""
|
@@ -86,19 +86,38 @@ description = """In this space you can warp an image using perspective transform
|
|
86 |
example_image = Image.open("bruce.png")
|
87 |
example_image_np = np.array(example_image)
|
88 |
|
89 |
-
|
90 |
-
gr.
|
91 |
-
gr.
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
inputs=inputs,
|
99 |
-
outputs=outputs,
|
100 |
-
title="Homography Warping",
|
101 |
-
description=description,
|
102 |
-
examples=[[example_image_np, "64", "128"]],
|
103 |
-
cache_examples=True
|
104 |
-
).launch()
|
|
|
34 |
|
35 |
def infer(image_input, dst_height: str, dst_width: str):
|
36 |
if isinstance(image_input, dict):
|
37 |
+
image_in = np.array(image_input['composite'])
|
38 |
+
mask_in = np.array(image_input['layers'][0]) if image_input['layers'] else np.zeros_like(image_in)
|
39 |
else:
|
40 |
image_in = image_input
|
41 |
mask_in = np.zeros_like(image_in)
|
|
|
77 |
|
78 |
description = """In this space you can warp an image using perspective transform with the Kornia library as seen in [this tutorial](https://kornia.github.io/tutorials/#category=Homography).
|
79 |
1. Upload an image or use the example provided
|
80 |
+
2. Set 4 points into the image using the brush tool, which define the area to warp
|
81 |
3. Set a desired output size (or go with the default)
|
82 |
4. Click Submit to run the demo
|
83 |
"""
|
|
|
86 |
example_image = Image.open("bruce.png")
|
87 |
example_image_np = np.array(example_image)
|
88 |
|
89 |
+
with gr.Blocks() as demo:
|
90 |
+
gr.Markdown("# Homography Warping")
|
91 |
+
gr.Markdown(description)
|
92 |
+
|
93 |
+
with gr.Row():
|
94 |
+
image_input = gr.ImageEditor(
|
95 |
+
type="numpy",
|
96 |
+
label="Input Image",
|
97 |
+
brush=gr.Brush(colors=["#ff0000"], size=5),
|
98 |
+
height=400,
|
99 |
+
width=600
|
100 |
+
)
|
101 |
+
output_plot = gr.Plot(label="Output")
|
102 |
+
|
103 |
+
with gr.Row():
|
104 |
+
dst_height = gr.Textbox(label="Destination Height", value="64")
|
105 |
+
dst_width = gr.Textbox(label="Destination Width", value="128")
|
106 |
+
|
107 |
+
submit_button = gr.Button("Submit")
|
108 |
+
submit_button.click(
|
109 |
+
fn=infer,
|
110 |
+
inputs=[image_input, dst_height, dst_width],
|
111 |
+
outputs=output_plot
|
112 |
+
)
|
113 |
+
|
114 |
+
gr.Examples(
|
115 |
+
examples=[[example_image_np, "64", "128"]],
|
116 |
+
inputs=[image_input, dst_height, dst_width],
|
117 |
+
outputs=output_plot,
|
118 |
+
fn=infer,
|
119 |
+
cache_examples=True
|
120 |
+
)
|
121 |
|
122 |
+
if __name__ == "__main__":
|
123 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|