Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ from vincenty import vincenty
|
|
| 15 |
import json
|
| 16 |
from collections import Counter
|
| 17 |
import mediapy
|
|
|
|
| 18 |
|
| 19 |
#from depth_anything.dpt import DepthAnything
|
| 20 |
#from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
|
|
@@ -58,6 +59,15 @@ def zip_files(files_in, files_out):
|
|
| 58 |
zipObj.write(file, file.split("/")[-1])
|
| 59 |
return "depth_result.zip"
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def create_video(frames, fps, type):
|
| 62 |
print("building video result")
|
| 63 |
imgs = []
|
|
@@ -159,6 +169,7 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data
|
|
| 159 |
depth_frames = []
|
| 160 |
orig_frames = []
|
| 161 |
backup_frames = []
|
|
|
|
| 162 |
thumbnail_old = []
|
| 163 |
|
| 164 |
while raw_video.isOpened():
|
|
@@ -222,15 +233,11 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data
|
|
| 222 |
thumbnail_old = thumbnail
|
| 223 |
|
| 224 |
blur_frame = blur_image(raw_frame, depth_color, blur_data)
|
|
|
|
|
|
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
depth_r = int(depth_gray / 17).astype(np.uint8)
|
| 229 |
-
# may use green channel for 16 levels of opacity
|
| 230 |
-
depth_b = depth_gray - depth_r * 17
|
| 231 |
-
blur_frame[:,:,0] = blur_frame[:,:,0] + depth_r
|
| 232 |
-
# blur_frame[:,:,1] = blur_frame[:,:,1] + opacity_g
|
| 233 |
-
blur_frame[:,:,2] = blur_frame[:,:,2] + depth_b
|
| 234 |
|
| 235 |
cv2.imwrite(f"f{count}.jpg", blur_frame)
|
| 236 |
orig_frames.append(f"f{count}.jpg")
|
|
@@ -250,6 +257,7 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data
|
|
| 250 |
|
| 251 |
final_vid = create_video(orig_frames, frame_rate, "orig")
|
| 252 |
depth_vid = create_video(depth_frames, frame_rate, "depth")
|
|
|
|
| 253 |
|
| 254 |
final_zip = zip_files(orig_frames, depth_frames)
|
| 255 |
raw_video.release()
|
|
@@ -272,7 +280,7 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits', blur_data
|
|
| 272 |
else:
|
| 273 |
gradient = cv2.imread('./gradient_small.png').astype(np.uint8)
|
| 274 |
|
| 275 |
-
return
|
| 276 |
|
| 277 |
def depth_edges_mask(depth):
|
| 278 |
"""Returns a mask of edges in the depth map.
|
|
|
|
| 15 |
import json
|
| 16 |
from collections import Counter
|
| 17 |
import mediapy
|
| 18 |
+
import ffmpy
|
| 19 |
|
| 20 |
#from depth_anything.dpt import DepthAnything
|
| 21 |
#from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
|
|
|
|
| 59 |
zipObj.write(file, file.split("/")[-1])
|
| 60 |
return "depth_result.zip"
|
| 61 |
|
| 62 |
+
def create_alpha_video(frames, fps, type):
|
| 63 |
+
print("building composite video result")
|
| 64 |
+
imgs = []
|
| 65 |
+
for j, img in enumerate(frames):
|
| 66 |
+
imgs.append(cv2.cvtColor(cv2.imread(img).astype(np.uint8), cv2.COLOR_RGBA2RGB))
|
| 67 |
+
|
| 68 |
+
mediapy.write_video(type + "_result.mp4", imgs, fps=fps)
|
| 69 |
+
return type + "_result.mp4"
|
| 70 |
+
|
| 71 |
def create_video(frames, fps, type):
|
| 72 |
print("building video result")
|
| 73 |
imgs = []
|
|
|
|
| 169 |
depth_frames = []
|
| 170 |
orig_frames = []
|
| 171 |
backup_frames = []
|
| 172 |
+
rgba_frames = []
|
| 173 |
thumbnail_old = []
|
| 174 |
|
| 175 |
while raw_video.isOpened():
|
|
|
|
| 233 |
thumbnail_old = thumbnail
|
| 234 |
|
| 235 |
blur_frame = blur_image(raw_frame, depth_color, blur_data)
|
| 236 |
+
rgba_frame = cv2.cvtColor(cv2.cvtColor(blur_frame, cv2.COLOR_BGR2RGB), cv2.COLOR_RGB2RGBA)
|
| 237 |
+
rgba_frame[:,:,3] = depth_gray
|
| 238 |
|
| 239 |
+
cv2.imwrite(f"f{count}.png", rgba_frame)
|
| 240 |
+
rgba_frames.append(f"f{count}.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
cv2.imwrite(f"f{count}.jpg", blur_frame)
|
| 243 |
orig_frames.append(f"f{count}.jpg")
|
|
|
|
| 257 |
|
| 258 |
final_vid = create_video(orig_frames, frame_rate, "orig")
|
| 259 |
depth_vid = create_video(depth_frames, frame_rate, "depth")
|
| 260 |
+
alpha_vid = create_alpha_video(rgba_frames, frame_rate, "rgba")
|
| 261 |
|
| 262 |
final_zip = zip_files(orig_frames, depth_frames)
|
| 263 |
raw_video.release()
|
|
|
|
| 280 |
else:
|
| 281 |
gradient = cv2.imread('./gradient_small.png').astype(np.uint8)
|
| 282 |
|
| 283 |
+
return alpha_vid, final_zip, frames, masks[frame_selected], depths, depth_vid #output_path
|
| 284 |
|
| 285 |
def depth_edges_mask(depth):
|
| 286 |
"""Returns a mask of edges in the depth map.
|