ghostsInTheMachine
commited on
Commit
•
c2e328f
1
Parent(s):
1963b01
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import shutil
|
|
6 |
import time
|
7 |
import ffmpeg
|
8 |
import numpy as np
|
9 |
-
from PIL import Image
|
10 |
import moviepy.editor as mp
|
11 |
from infer import lotus, load_models
|
12 |
import logging
|
@@ -33,21 +33,8 @@ def preprocess_video(video_path, target_fps=24):
|
|
33 |
|
34 |
return video
|
35 |
|
36 |
-
# Resize image while preserving aspect ratio and adding padding
|
37 |
-
def resize_and_pad(image, target_size):
|
38 |
-
"""Resize and pad an image to the target size while preserving aspect ratio."""
|
39 |
-
# Calculate the new size preserving aspect ratio
|
40 |
-
image.thumbnail(target_size, Image.LANCZOS)
|
41 |
-
|
42 |
-
# Create a new image with the target size and black background
|
43 |
-
new_image = Image.new("RGB", target_size)
|
44 |
-
new_image.paste(
|
45 |
-
image, ((target_size[0] - image.width) // 2, (target_size[1] - image.height) // 2)
|
46 |
-
)
|
47 |
-
return new_image
|
48 |
-
|
49 |
# Process a single frame through the depth model
|
50 |
-
def process_frame(frame, seed=0
|
51 |
"""Process a single frame and return depth map."""
|
52 |
try:
|
53 |
torch.cuda.empty_cache() # Clear GPU cache
|
@@ -55,21 +42,10 @@ def process_frame(frame, seed=0, target_size=(1024, 1024)):
|
|
55 |
# Convert frame to PIL Image
|
56 |
image = Image.fromarray(frame).convert('RGB')
|
57 |
|
58 |
-
#
|
59 |
-
|
60 |
-
|
61 |
-
# Run inference
|
62 |
-
depth_map = lotus(input_image, 'depth', seed, device, pipe_g, pipe_d)
|
63 |
-
|
64 |
-
# Crop the output depth map back to original image size
|
65 |
-
width, height = image.size
|
66 |
-
left = (target_size[0] - width) // 2
|
67 |
-
top = (target_size[1] - height) // 2
|
68 |
-
right = left + width
|
69 |
-
bottom = top + height
|
70 |
-
depth_map_cropped = depth_map.crop((left, top, right, bottom))
|
71 |
|
72 |
-
return
|
73 |
|
74 |
except Exception as e:
|
75 |
logger.error(f"Error processing frame: {e}")
|
|
|
6 |
import time
|
7 |
import ffmpeg
|
8 |
import numpy as np
|
9 |
+
from PIL import Image
|
10 |
import moviepy.editor as mp
|
11 |
from infer import lotus, load_models
|
12 |
import logging
|
|
|
33 |
|
34 |
return video
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
# Process a single frame through the depth model
|
37 |
+
def process_frame(frame, seed=0):
|
38 |
"""Process a single frame and return depth map."""
|
39 |
try:
|
40 |
torch.cuda.empty_cache() # Clear GPU cache
|
|
|
42 |
# Convert frame to PIL Image
|
43 |
image = Image.fromarray(frame).convert('RGB')
|
44 |
|
45 |
+
# Run inference without resizing
|
46 |
+
depth_map = lotus(image, 'depth', seed, device, pipe_g, pipe_d)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
return depth_map
|
49 |
|
50 |
except Exception as e:
|
51 |
logger.error(f"Error processing frame: {e}")
|