Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -111,15 +111,15 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
|
|
111 |
#out = cv2.VideoWriter(output_path, fourcc, frame_rate, (output_width, frame_height))
|
112 |
count=0
|
113 |
depth_frames = []
|
|
|
114 |
orig_frames = []
|
115 |
while raw_video.isOpened():
|
116 |
ret, raw_frame = raw_video.read()
|
117 |
if not ret:
|
118 |
break
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
frame_pil = Image.fromarray(raw_frame)
|
123 |
frame = transform({'image': frame})['image']
|
124 |
|
125 |
frame = torch.from_numpy(frame).unsqueeze(0).to(DEVICE)
|
@@ -132,8 +132,8 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
|
|
132 |
|
133 |
depth = depth.cpu().numpy().astype(np.uint8)
|
134 |
depth_color = cv2.applyColorMap(depth, cv2.COLORMAP_BONE)
|
135 |
-
|
136 |
-
depth_color = cv2.cvtColor(
|
137 |
|
138 |
# Remove white border around map:
|
139 |
# define lower and upper limits of white
|
@@ -155,6 +155,8 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
|
|
155 |
orig_frames.append(f"f{count}.jpg")
|
156 |
cv2.imwrite(f"f{count}_dmap.jpg", depth_color)
|
157 |
depth_frames.append(f"f{count}_dmap.jpg")
|
|
|
|
|
158 |
count += 1
|
159 |
|
160 |
final_vid = create_video(depth_frames, frame_rate, "depth")
|
@@ -163,7 +165,7 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
|
|
163 |
# out.release()
|
164 |
cv2.destroyAllWindows()
|
165 |
|
166 |
-
return final_vid, final_zip, orig_frames[0],
|
167 |
|
168 |
def depth_edges_mask(depth):
|
169 |
"""Returns a mask of edges in the depth map.
|
|
|
111 |
#out = cv2.VideoWriter(output_path, fourcc, frame_rate, (output_width, frame_height))
|
112 |
count=0
|
113 |
depth_frames = []
|
114 |
+
gdepth_frames = []
|
115 |
orig_frames = []
|
116 |
while raw_video.isOpened():
|
117 |
ret, raw_frame = raw_video.read()
|
118 |
if not ret:
|
119 |
break
|
120 |
|
121 |
+
frame = cv2.cvtColor(raw_frame, cv2.COLOR_BGR2RGB) / 255.0
|
122 |
+
frame_pil = Image.fromarray((frame * 255).astype(np.uint8))
|
|
|
123 |
frame = transform({'image': frame})['image']
|
124 |
|
125 |
frame = torch.from_numpy(frame).unsqueeze(0).to(DEVICE)
|
|
|
132 |
|
133 |
depth = depth.cpu().numpy().astype(np.uint8)
|
134 |
depth_color = cv2.applyColorMap(depth, cv2.COLORMAP_BONE)
|
135 |
+
depth_gray = cv2.cvtColor(depth_color, cv2.COLOR_RGBA2GRAY)
|
136 |
+
depth_color = cv2.cvtColor(depth_gray, cv2.COLOR_GRAY2RGB)
|
137 |
|
138 |
# Remove white border around map:
|
139 |
# define lower and upper limits of white
|
|
|
155 |
orig_frames.append(f"f{count}.jpg")
|
156 |
cv2.imwrite(f"f{count}_dmap.jpg", depth_color)
|
157 |
depth_frames.append(f"f{count}_dmap.jpg")
|
158 |
+
cv2.imwrite(f"f{count}_gmap.jpg", depth_gray)
|
159 |
+
gdepth_frames.append(f"f{count}_gmap.jpg")
|
160 |
count += 1
|
161 |
|
162 |
final_vid = create_video(depth_frames, frame_rate, "depth")
|
|
|
165 |
# out.release()
|
166 |
cv2.destroyAllWindows()
|
167 |
|
168 |
+
return final_vid, final_zip, orig_frames[0], gdepth_frames[0] #output_path
|
169 |
|
170 |
def depth_edges_mask(depth):
|
171 |
"""Returns a mask of edges in the depth map.
|