Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ZaiqiangWu committed Jul 31, 2024
1 parent 617037e commit 21a8629
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
9 changes: 4 additions & 5 deletions run/run_ootd_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from preprocess.humanparsing.run_parsing import Parsing
from ootd.inference_ootd_hd import OOTDiffusionHD
from ootd.inference_ootd_dc import OOTDiffusionDC
from util.image_warp import ImageReshaper,crop2_43
from util.image_warp import crop2_43


import argparse
Expand Down Expand Up @@ -67,8 +67,7 @@ def __init__(self,cloth_path):
def forward(self,frame:np.ndarray):
frame=frame[:,:,[2,1,0]]
frame=Image.fromarray(frame)
img_reshaper=ImageReshaper(frame)
frame_43=img_reshaper.get_reshaped()
frame_43=crop2_43(frame)
model_img = frame_43.resize((768,1024))
keypoints = openpose_model(model_img.resize((384, 512)))
model_parse, _ = parsing_model(model_img.resize((384, 512)))
Expand All @@ -94,8 +93,8 @@ def forward(self,frame:np.ndarray):
)

result=images[0]
raw_result=img_reshaper.back2rawSahpe(result)
return raw_result[:,:,[2,1,0]]
result=np.array(result)
return result[:,:,[2,1,0]]

from util.video_loader import VideoLoader
from util.image2video import Image2VideoWriter
Expand Down
35 changes: 32 additions & 3 deletions util/image_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,39 @@
import numpy as np


def crop2_43(img: Image.Image):
img_reshaper = ImageReshaper(img)
return img_reshaper.get_reshaped()
def crop2_43(img):
if isinstance(img, Image.Image):
# Convert PIL image to NumPy array
img = np.array(img)
pil_input = True
elif isinstance(img, np.ndarray):
pil_input = False
else:
raise TypeError("Input must be a PIL Image or a NumPy array.")

h, w = img.shape[:2]
if 3 * h > 4 * w: # too tall
delta = h - w * 4 / 3
img = img[int(delta / 2):h - int(delta / 2), :, :]
else:
delta = w - h * 3 / 4
img = img[:, int(delta / 2):w - int(delta / 2), :]

if pil_input:
# Convert NumPy array back to PIL image
img = Image.fromarray(img)

return img

def crop2_169(img: np.ndarray) -> np.ndarray:
h,w=img.shape[:2]
if 9*h>16*w:#too tall
delta=h-w*16/9
img=img[int(delta/2):h-int(delta/2),:,:]
else:
delta = w-h*9/16
img = img[:,int(delta / 2):w - int(delta / 2), :]
return img

class ImageReshaper:
def __init__(self, img: Image.Image):
Expand Down

0 comments on commit 21a8629

Please sign in to comment.