Update app.py
Browse files
app.py
CHANGED
@@ -114,6 +114,8 @@ def pipe_inference(
|
|
114 |
return all_outputs
|
115 |
|
116 |
def resize_image(image, resolution):
|
|
|
|
|
117 |
h, w = image.shape[:2]
|
118 |
ratio = w/h
|
119 |
if ratio > 1 :
|
@@ -122,10 +124,14 @@ def resize_image(image, resolution):
|
|
122 |
resized_image = cv2.resize(image, (resolution, int(resolution/ratio)), interpolation=cv2.INTER_NEAREST)
|
123 |
else:
|
124 |
resized_image = cv2.resize(image, (resolution, resolution), interpolation=cv2.INTER_NEAREST)
|
125 |
-
|
|
|
126 |
|
127 |
|
128 |
def preprocess_canny(image, resolution=128):
|
|
|
|
|
|
|
129 |
processed_image = cv2.Canny(image, low_threshold, high_threshold)
|
130 |
processed_image = processed_image[:, :, None]
|
131 |
processed_image = np.concatenate([processed_image, processed_image, processed_image], axis=2)
|
|
|
114 |
return all_outputs
|
115 |
|
116 |
def resize_image(image, resolution):
|
117 |
+
if not isinstance(image, np.ndarray):
|
118 |
+
image = np.array(image)
|
119 |
h, w = image.shape[:2]
|
120 |
ratio = w/h
|
121 |
if ratio > 1 :
|
|
|
124 |
resized_image = cv2.resize(image, (resolution, int(resolution/ratio)), interpolation=cv2.INTER_NEAREST)
|
125 |
else:
|
126 |
resized_image = cv2.resize(image, (resolution, resolution), interpolation=cv2.INTER_NEAREST)
|
127 |
+
|
128 |
+
return Image.fromarray(resized_image)
|
129 |
|
130 |
|
131 |
def preprocess_canny(image, resolution=128):
|
132 |
+
if not isinstance(image, np.ndarray):
|
133 |
+
image = np.array(image)
|
134 |
+
|
135 |
processed_image = cv2.Canny(image, low_threshold, high_threshold)
|
136 |
processed_image = processed_image[:, :, None]
|
137 |
processed_image = np.concatenate([processed_image, processed_image, processed_image], axis=2)
|