Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,14 @@ import spaces
|
|
13 |
|
14 |
from depth_anything.dpt import DepthAnything
|
15 |
from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
@torch.no_grad()
|
18 |
def predict_depth(model, image):
|
@@ -82,7 +90,8 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
|
|
82 |
#out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"avc1"), frame_rate, (output_width, frame_height))
|
83 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
84 |
out = cv2.VideoWriter(output_path, fourcc, frame_rate, (output_width, frame_height))
|
85 |
-
|
|
|
86 |
while raw_video.isOpened():
|
87 |
ret, raw_frame = raw_video.read()
|
88 |
if not ret:
|
@@ -109,12 +118,16 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
|
|
109 |
# out.write(combined_frame)
|
110 |
# frame_path = os.path.join(temp_frame_dir, f"frame_{count:05d}.png")
|
111 |
# cv2.imwrite(frame_path, combined_frame)
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
|
|
115 |
raw_video.release()
|
116 |
out.release()
|
117 |
-
|
|
|
|
|
118 |
|
119 |
def loadurl(url):
|
120 |
return url
|
|
|
13 |
|
14 |
from depth_anything.dpt import DepthAnything
|
15 |
from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
|
16 |
+
from moviepy.editor import *
|
17 |
+
|
18 |
+
def create_video(frames, fps, type):
|
19 |
+
print("building video result")
|
20 |
+
clip = ImageSequenceClip(frames, fps=fps)
|
21 |
+
clip.write_videofile(type + "_result.mp4", fps=fps)
|
22 |
+
|
23 |
+
return type + "_result.mp4"
|
24 |
|
25 |
@torch.no_grad()
|
26 |
def predict_depth(model, image):
|
|
|
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():
|
96 |
ret, raw_frame = raw_video.read()
|
97 |
if not ret:
|
|
|
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", combined_frame)
|
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
|
131 |
|
132 |
def loadurl(url):
|
133 |
return url
|