freealise commited on
Commit
f6913f3
1 Parent(s): 9801af7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
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
- # count=0
 
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
- out.write(combined_frame)
113
- # count += 1
114
-
 
 
115
  raw_video.release()
116
  out.release()
117
- return output_path
 
 
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