Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
mischeiwiller
commited on
Commit
•
e43d011
1
Parent(s):
cd899a2
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import cv2
|
|
5 |
import numpy as np
|
6 |
import matplotlib.pyplot as plt
|
7 |
from scipy.cluster.vq import kmeans
|
|
|
8 |
|
9 |
def get_coordinates_from_mask(mask_in):
|
10 |
x_y = np.where(mask_in != [0,0,0,255])[:2]
|
@@ -32,8 +33,13 @@ def sort_centroids_clockwise(centroids: np.ndarray):
|
|
32 |
return top_left, top_right, bottom_right, bottom_left
|
33 |
|
34 |
def infer(image_input, dst_height: str, dst_width: str):
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
torch_img = K.utils.image_to_tensor(image_in).float() / 255.0
|
38 |
|
39 |
centroids = get_coordinates_from_mask(mask_in)
|
@@ -76,16 +82,15 @@ description = """In this space you can warp an image using perspective transform
|
|
76 |
4. Click Submit to run the demo
|
77 |
"""
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
|
83 |
inputs = [
|
84 |
-
gr.Image(type="numpy", label="Input Image"),
|
85 |
gr.Textbox(label="Destination Height", value="64"),
|
86 |
gr.Textbox(label="Destination Width", value="128"),
|
87 |
]
|
88 |
-
|
89 |
outputs = gr.Plot(label="Output")
|
90 |
|
91 |
gr.Interface(
|
@@ -94,6 +99,6 @@ gr.Interface(
|
|
94 |
outputs=outputs,
|
95 |
title="Homography Warping",
|
96 |
description=description,
|
97 |
-
examples=[[
|
98 |
cache_examples=True
|
99 |
).launch()
|
|
|
5 |
import numpy as np
|
6 |
import matplotlib.pyplot as plt
|
7 |
from scipy.cluster.vq import kmeans
|
8 |
+
from PIL import Image
|
9 |
|
10 |
def get_coordinates_from_mask(mask_in):
|
11 |
x_y = np.where(mask_in != [0,0,0,255])[:2]
|
|
|
33 |
return top_left, top_right, bottom_right, bottom_left
|
34 |
|
35 |
def infer(image_input, dst_height: str, dst_width: str):
|
36 |
+
if isinstance(image_input, dict):
|
37 |
+
image_in = image_input["image"]
|
38 |
+
mask_in = image_input["mask"]
|
39 |
+
else:
|
40 |
+
image_in = image_input
|
41 |
+
mask_in = np.zeros_like(image_in)
|
42 |
+
|
43 |
torch_img = K.utils.image_to_tensor(image_in).float() / 255.0
|
44 |
|
45 |
centroids = get_coordinates_from_mask(mask_in)
|
|
|
82 |
4. Click Submit to run the demo
|
83 |
"""
|
84 |
|
85 |
+
# Load the example image
|
86 |
+
example_image = Image.open("bruce.png")
|
87 |
+
example_image_np = np.array(example_image)
|
88 |
|
89 |
inputs = [
|
90 |
+
gr.Image(type="numpy", label="Input Image", tool="sketch"),
|
91 |
gr.Textbox(label="Destination Height", value="64"),
|
92 |
gr.Textbox(label="Destination Width", value="128"),
|
93 |
]
|
|
|
94 |
outputs = gr.Plot(label="Output")
|
95 |
|
96 |
gr.Interface(
|
|
|
99 |
outputs=outputs,
|
100 |
title="Homography Warping",
|
101 |
description=description,
|
102 |
+
examples=[[example_image_np, "64", "128"]],
|
103 |
cache_examples=True
|
104 |
).launch()
|