rotate option for cropper

This commit is contained in:
kijai
2024-07-09 23:02:47 +03:00
parent 1b080706df
commit eecf645603
3 changed files with 9 additions and 7 deletions
+1 -1
View File
@@ -357,7 +357,7 @@ def crop_image(img, pts: np.ndarray, **kwargs):
scale=scale,
vy_ratio=vy_ratio,
vx_ratio=vx_ratio,
flag_do_rot=kwargs.get('flag_do_rot', True),
flag_do_rot=kwargs.get('rotate', True),
)
if img is None:
+4 -3
View File
@@ -42,7 +42,7 @@ class Cropper(object):
self.face_analysis_wrapper.prepare(ctx_id=device_id, det_size=(512, 512))
self.face_analysis_wrapper.warmup()
def crop_single_image(self, img_rgb, dsize, scale, vy_ratio, vx_ratio, face_index):
def crop_single_image(self, img_rgb, dsize, scale, vy_ratio, vx_ratio, face_index, rotate):
direction = 'large-small'
src_face = self.face_analysis_wrapper.get(
@@ -66,7 +66,8 @@ class Cropper(object):
dsize=dsize,
scale=scale,
vy_ratio=vy_ratio,
vx_ratio=vx_ratio
vx_ratio=vx_ratio,
rotate=rotate
)
# update a 256x256 version for network input or else
ret_dct['img_crop_256x256'] = cv2.resize(ret_dct['img_crop'], (256, 256), interpolation=cv2.INTER_AREA)
@@ -79,4 +80,4 @@ class Cropper(object):
lmk = recon_ret['pts']
ret_dct['lmk_crop'] = lmk
return ret_dct
return ret_dct
+4 -3
View File
@@ -333,6 +333,7 @@ class LivePortraitCropper:
"vx_ratio": ("FLOAT", {"default": 0.0, "min": -1.0, "max": 1.0, "step": 0.01}),
"vy_ratio": ("FLOAT", {"default": -0.125, "min": -1.0, "max": 1.0, "step": 0.01}),
"face_index": ("INT", {"default": 0, "min": 0, "max": 100}),
"rotate": ("BOOLEAN", {"default": True}),
"onnx_device": (
['CPU', 'CUDA', 'ROCM'], {
"default": 'CPU'
@@ -350,7 +351,7 @@ class LivePortraitCropper:
FUNCTION = "process"
CATEGORY = "LivePortrait"
def process(self, source_image, dsize, scale, vx_ratio, vy_ratio, face_index, keep_model_loaded, onnx_device='CUDA', opt_driving_images=None):
def process(self, source_image, dsize, scale, vx_ratio, vy_ratio, face_index, rotate, keep_model_loaded, onnx_device='CUDA', opt_driving_images=None):
source_image_np = (source_image * 255).byte().numpy()
cropper_init_config = {
@@ -371,13 +372,13 @@ class LivePortraitCropper:
pbar = comfy.utils.ProgressBar(len(source_image_np))
for i in tqdm(range(len(source_image_np)), desc='Detecting and cropping..', total=len(source_image_np)):
crop_info = self.cropper.crop_single_image(source_image_np[i], dsize, scale, vy_ratio, vx_ratio, face_index)
crop_info = self.cropper.crop_single_image(source_image_np[i], dsize, scale, vy_ratio, vx_ratio, face_index, rotate)
crop_info_list.append(crop_info)
cropped_image = crop_info['img_crop_256x256']
cropped_images_list.append(cropped_image)
if opt_driving_images is not None:
driving_crop_dict = self.cropper.crop_single_image(driving_images_np[i], dsize, scale, vy_ratio, vx_ratio, face_index)
driving_crop_dict = self.cropper.crop_single_image(driving_images_np[i], dsize, scale, vy_ratio, vx_ratio, face_index, rotate)
driving_landmark_list.append(driving_crop_dict['lmk_crop'])
pbar.update(1)