Skip to content

Commit

Permalink
[Refactor] cut and paste I/O 형식 변경 #33
Browse files Browse the repository at this point in the history
- cut and paste의 io를 in memory 방식으로 변경

related to : #31
  • Loading branch information
Hyunmin-H committed Aug 17, 2023
1 parent 6407f94 commit e132d86
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions model/ladi_vton/src/utils/face_cut_and_paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,37 @@
from PIL import Image, ImageDraw, ImageOps
import PIL
import os
import io
# /opt/ml/user_db/schp/buffer/target.png
import numpy as np

import matplotlib.pyplot as plt
from time import time


def main_cut_and_paste(category, db_dir, target_name='target.jpg'):
def main_cut_and_paste(category, target_bytes, finalResult_img, schp_img, target_name='target.jpg'):

dataroot = db_dir
im_name = target_name
generative_name = 'lower_body.png'
parse_name = im_name.replace('.jpg', '.png')


# /opt/ml/user_db/input/buffer/target/target.jpg

origin_image = Image.open(os.path.join(dataroot, 'input/buffer/target', im_name))
# origin_image = Image.open(os.path.join(dataroot, 'input/buffer/target', im_name))
origin_image = Image.open(io.BytesIO(target_bytes))
origin_image = origin_image.resize((384,512))
origin_np = np.array(origin_image)

# /opt/ml/user_db/ladi/buffer/lower_body.png

generatived_image = Image.open(os.path.join(dataroot, 'ladi/buffer', f'{category}.png'))
# generatived_image = Image.open(os.path.join(dataroot, 'ladi/buffer', f'{category}.png'))
generatived_image = finalResult_img
generatived_np = np.array(generatived_image)


im_parse = Image.open(os.path.join(dataroot, 'schp/buffer', parse_name))
# im_parse = Image.open(os.path.join(dataroot, 'schp/buffer', parse_name))
im_parse = schp_img
im_parse = im_parse.resize((384, 512), Image.NEAREST)
parse_array = np.array(im_parse)

Expand Down Expand Up @@ -102,4 +105,5 @@ def overlay_arrays(origin_np, generatived_np, indices):
# print('파일있냐')
# os.remove(file)

result_array.save(os.path.join(dataroot, 'ladi/buffer', f'{category}.png'))
return result_array
# result_array.save(os.path.join(dataroot, 'ladi/buffer', f'{category}.png'))

0 comments on commit e132d86

Please sign in to comment.