Spaces:
Runtime error
Runtime error
Commit
·
5112818
1
Parent(s):
2c2d3cf
Resize and normalize input image before processing
Browse files
app.py
CHANGED
|
@@ -75,20 +75,26 @@ with gr.Blocks(css=css) as demo:
|
|
| 75 |
type='numpy', elem_id='img-display-input')
|
| 76 |
depth_image_slider = ImageSlider(
|
| 77 |
label="Depth Map with Slider View", elem_id='img-display-output', position=0.5,)
|
| 78 |
-
raw_file = gr.File(
|
| 79 |
-
label="16-bit raw depth (can be considered as disparity)")
|
| 80 |
submit = gr.Button("Submit")
|
| 81 |
|
| 82 |
def on_submit(image):
|
| 83 |
original_image = image.copy()
|
| 84 |
|
| 85 |
-
#
|
|
|
|
| 86 |
h, w = image.shape[:2]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
|
|
|
| 88 |
image = np.asarray(image, dtype=np.float32) / 255.0
|
| 89 |
image = torch.from_numpy(image.transpose((2, 0, 1)))
|
| 90 |
image = Normalize(mean=[0.485, 0.456, 0.406], std=[
|
| 91 |
0.229, 0.224, 0.225])(image)
|
|
|
|
| 92 |
with torch.no_grad():
|
| 93 |
image = torch.autograd.Variable(image.unsqueeze(0))
|
| 94 |
print("== Processing image")
|
|
@@ -104,7 +110,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 104 |
|
| 105 |
# Continue with your file saving operations
|
| 106 |
tmp = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
| 107 |
-
# cv2.imwrite(tmp.name, output_image)
|
| 108 |
plt.imsave(tmp.name, pred_depth, cmap='jet')
|
| 109 |
|
| 110 |
return [(original_image, tmp.name), tmp.name]
|
|
|
|
| 75 |
type='numpy', elem_id='img-display-input')
|
| 76 |
depth_image_slider = ImageSlider(
|
| 77 |
label="Depth Map with Slider View", elem_id='img-display-output', position=0.5,)
|
| 78 |
+
raw_file = gr.File(label="Download Depth Map")
|
|
|
|
| 79 |
submit = gr.Button("Submit")
|
| 80 |
|
| 81 |
def on_submit(image):
|
| 82 |
original_image = image.copy()
|
| 83 |
|
| 84 |
+
# Resize the image if it is larger than 640x480
|
| 85 |
+
max_width, max_height = 640, 480
|
| 86 |
h, w = image.shape[:2]
|
| 87 |
+
if w > max_width or h > max_height:
|
| 88 |
+
scaling_factor = min(max_width / w, max_height / h)
|
| 89 |
+
image = cv2.resize(image, None, fx=scaling_factor,
|
| 90 |
+
fy=scaling_factor, interpolation=cv2.INTER_AREA)
|
| 91 |
|
| 92 |
+
# Normalize the image
|
| 93 |
image = np.asarray(image, dtype=np.float32) / 255.0
|
| 94 |
image = torch.from_numpy(image.transpose((2, 0, 1)))
|
| 95 |
image = Normalize(mean=[0.485, 0.456, 0.406], std=[
|
| 96 |
0.229, 0.224, 0.225])(image)
|
| 97 |
+
|
| 98 |
with torch.no_grad():
|
| 99 |
image = torch.autograd.Variable(image.unsqueeze(0))
|
| 100 |
print("== Processing image")
|
|
|
|
| 110 |
|
| 111 |
# Continue with your file saving operations
|
| 112 |
tmp = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
|
|
|
| 113 |
plt.imsave(tmp.name, pred_depth, cmap='jet')
|
| 114 |
|
| 115 |
return [(original_image, tmp.name), tmp.name]
|