Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -80,16 +80,17 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
|
|
80 |
raw_video = cv2.VideoCapture(filename)
|
81 |
frame_width, frame_height = int(raw_video.get(cv2.CAP_PROP_FRAME_WIDTH)), int(raw_video.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
82 |
frame_rate = int(raw_video.get(cv2.CAP_PROP_FPS))
|
83 |
-
|
84 |
-
|
|
|
85 |
|
86 |
-
filename = os.path.basename(filename)
|
87 |
# output_path = os.path.join(outdir, filename[:filename.rfind('.')] + '_video_depth.mp4')
|
88 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmpfile:
|
89 |
-
|
90 |
#out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"avc1"), frame_rate, (output_width, frame_height))
|
91 |
-
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
92 |
-
out = cv2.VideoWriter(output_path, fourcc, frame_rate, (output_width, frame_height))
|
93 |
count=0
|
94 |
depth_frames = []
|
95 |
while raw_video.isOpened():
|
@@ -111,20 +112,21 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
|
|
111 |
|
112 |
depth = depth.cpu().numpy().astype(np.uint8)
|
113 |
depth_color = cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO)
|
|
|
114 |
|
115 |
-
split_region = np.ones((frame_height, margin_width, 3), dtype=np.uint8) * 255
|
116 |
-
combined_frame = cv2.hconcat([raw_frame, split_region, depth_color])
|
117 |
|
118 |
# out.write(combined_frame)
|
119 |
# frame_path = os.path.join(temp_frame_dir, f"frame_{count:05d}.png")
|
120 |
# cv2.imwrite(frame_path, combined_frame)
|
121 |
-
cv2.imwrite(f"frame{count}.jpg",
|
122 |
depth_frames.append(f"frame{count}.jpg")
|
123 |
count += 1
|
124 |
|
125 |
final_vid = create_video(depth_frames, frame_rate, "depth")
|
126 |
raw_video.release()
|
127 |
-
out.release()
|
128 |
cv2.destroyAllWindows()
|
129 |
|
130 |
return final_vid #output_path
|
|
|
80 |
raw_video = cv2.VideoCapture(filename)
|
81 |
frame_width, frame_height = int(raw_video.get(cv2.CAP_PROP_FRAME_WIDTH)), int(raw_video.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
82 |
frame_rate = int(raw_video.get(cv2.CAP_PROP_FPS))
|
83 |
+
cframes = int(raw_video.get(cv2.CAP_PROP_FRAME_COUNT))
|
84 |
+
print(f'frames: {cframes}, fps: {frame_rate}')
|
85 |
+
# output_width = frame_width * 2 + margin_width
|
86 |
|
87 |
+
#filename = os.path.basename(filename)
|
88 |
# output_path = os.path.join(outdir, filename[:filename.rfind('.')] + '_video_depth.mp4')
|
89 |
+
#with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmpfile:
|
90 |
+
# output_path = tmpfile.name
|
91 |
#out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"avc1"), frame_rate, (output_width, frame_height))
|
92 |
+
#fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
93 |
+
#out = cv2.VideoWriter(output_path, fourcc, frame_rate, (output_width, frame_height))
|
94 |
count=0
|
95 |
depth_frames = []
|
96 |
while raw_video.isOpened():
|
|
|
112 |
|
113 |
depth = depth.cpu().numpy().astype(np.uint8)
|
114 |
depth_color = cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO)
|
115 |
+
#depth_color = cv2.cvtColor(depth_color, cv2.COLOR_GRAY2RGB)
|
116 |
|
117 |
+
# split_region = np.ones((frame_height, margin_width, 3), dtype=np.uint8) * 255
|
118 |
+
# combined_frame = cv2.hconcat([raw_frame, split_region, depth_color])
|
119 |
|
120 |
# out.write(combined_frame)
|
121 |
# frame_path = os.path.join(temp_frame_dir, f"frame_{count:05d}.png")
|
122 |
# cv2.imwrite(frame_path, combined_frame)
|
123 |
+
cv2.imwrite(f"frame{count}.jpg", depth_color)
|
124 |
depth_frames.append(f"frame{count}.jpg")
|
125 |
count += 1
|
126 |
|
127 |
final_vid = create_video(depth_frames, frame_rate, "depth")
|
128 |
raw_video.release()
|
129 |
+
# out.release()
|
130 |
cv2.destroyAllWindows()
|
131 |
|
132 |
return final_vid #output_path
|