oxkitsune commited on
Commit
e9ee731
·
1 Parent(s): 8465eec

fix visualization

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -26,7 +26,7 @@ model = model.to(device)
26
  model.eval()
27
 
28
 
29
- def resize_image(image_buffer, max_size=128):
30
  with Image.fromarray(image_buffer) as img:
31
  # Calculate the new size while maintaining aspect ratio
32
  ratio = max_size / max(img.size)
@@ -109,27 +109,30 @@ def run_rerun(path_to_video):
109
 
110
  temp_file = None
111
  try:
112
- temp_file = resize_image(frame, max_size=128)
 
113
 
114
  depth, focal_length = predict_depth(temp_file)
115
 
116
- # scale the depth image to the original frame size
117
- depth = cv2.resize(
118
- depth, (frame.shape[1], frame.shape[0]), interpolation=cv2.INTER_NEAREST
119
- )
120
 
121
  rr.set_time_nanos("video_time", frame_timestamps_ns[i])
122
  rr.log(
123
  "world/camera/depth",
124
- rr.DepthImage(depth, meter=1, depth_range=(0, 10)),
125
  )
126
 
127
  rr.log(
128
  "world/camera/frame",
129
  rr.VideoFrameReference(
130
- timestamp=rr.components.VideoTimestamp(seconds=1.0),
 
 
131
  video_reference="world/video",
132
  ),
 
133
  )
134
 
135
  rr.log(
@@ -170,12 +173,20 @@ with gr.Blocks() as interface:
170
  """
171
  # DepthPro Rerun Demo
172
 
173
- [DepthPro](https://huggingface.co/apple/DepthPro) is a fast metric depth prediction model. Simply upload an image to predict its inverse depth map and focal length. Large images will be automatically resized to 1536x1536 pixels.
 
 
174
  """
175
  )
176
  with gr.Row():
177
  with gr.Column(variant="compact"):
178
- video = gr.Video(format="mp4", interactive=True, label="Video")
 
 
 
 
 
 
179
  visualize = gr.Button("Visualize ML Depth Pro")
180
  with gr.Column():
181
  viewer = Rerun(
 
26
  model.eval()
27
 
28
 
29
+ def resize_image(image_buffer, max_size=256):
30
  with Image.fromarray(image_buffer) as img:
31
  # Calculate the new size while maintaining aspect ratio
32
  ratio = max_size / max(img.size)
 
109
 
110
  temp_file = None
111
  try:
112
+ # Resize the image to make the inference faster
113
+ temp_file = resize_image(frame, max_size=256)
114
 
115
  depth, focal_length = predict_depth(temp_file)
116
 
117
+ # find x and y scale factors, which can be applied to image
118
+ x_scale = depth.shape[1] / frame.shape[1]
119
+ y_scale = depth.shape[0] / frame.shape[0]
 
120
 
121
  rr.set_time_nanos("video_time", frame_timestamps_ns[i])
122
  rr.log(
123
  "world/camera/depth",
124
+ rr.DepthImage(depth, meter=1),
125
  )
126
 
127
  rr.log(
128
  "world/camera/frame",
129
  rr.VideoFrameReference(
130
+ timestamp=rr.components.VideoTimestamp(
131
+ nanoseconds=frame_timestamps_ns[i]
132
+ ),
133
  video_reference="world/video",
134
  ),
135
+ rr.Transform3D(scale=(x_scale, y_scale, 1)),
136
  )
137
 
138
  rr.log(
 
173
  """
174
  # DepthPro Rerun Demo
175
 
176
+ [DepthPro](https://huggingface.co/apple/DepthPro) is a fast metric depth prediction model. Simply upload an image to predict its inverse depth map and focal length.
177
+
178
+ High resolution videos will be automatically resized to 256x256 pixels, to speed up the inference and visualize multiple frames.
179
  """
180
  )
181
  with gr.Row():
182
  with gr.Column(variant="compact"):
183
+ video = gr.Video(
184
+ format="mp4",
185
+ interactive=True,
186
+ label="Video",
187
+ include_audio=False,
188
+ max_length=10,
189
+ )
190
  visualize = gr.Button("Visualize ML Depth Pro")
191
  with gr.Column():
192
  viewer = Rerun(