diff --git a/hellomeme/tools/hello_camera_demo.py b/hellomeme/tools/hello_camera_demo.py index 105d3ae..353690e 100644 --- a/hellomeme/tools/hello_camera_demo.py +++ b/hellomeme/tools/hello_camera_demo.py @@ -225,7 +225,7 @@ class Smoother222(object): class HelloCameraDemo(object): def __init__(self, face_alignment_module, reset=False): self.face_alignment_module = face_alignment_module - self.face_prob_th = 0.01 + self.face_prob_th = 0.0001 self.min_face = 96 self.face_image_size = self.face_alignment_module.face_image_size self.trackingFaces = [] diff --git a/hellomeme/utils.py b/hellomeme/utils.py index 929a060..de3d046 100644 --- a/hellomeme/utils.py +++ b/hellomeme/utils.py @@ -310,10 +310,9 @@ def crop_and_resize(frames, landmarks, save_size=512, crop=True): tl, br = np.min(all_tl, axis=0), np.max(all_br, axis=0) new_size = min(max(mean_wh) * 2.5, min(H, W) - 1) fcenter = (tl + br) * 0.5 + fcenter[1] -= new_size * 0.12 ftl = fcenter - new_size * 0.5 - ftl[1] -= mean_wh[1] * 0.2 fbr = fcenter + new_size * 0.5 - fbr[1] -= mean_wh[1] * 0.2 if ftl[0] < 0: fbr[0] -= ftl[0] @@ -328,12 +327,23 @@ def crop_and_resize(frames, landmarks, save_size=512, crop=True): if fbr[1] >= H: ftl[1] -= fbr[1] - H + 1 fbr[1] = H - 1 - ftl = ftl.astype(int) - fbr = (fbr - ftl)[0].astype(int) + ftl - frames = frames[:, ftl[1]:fbr[1], ftl[0]:fbr[0], :].copy() - landmarks = landmarks - ftl - ratio = save_size / (fbr - ftl) + opt_center = (ftl + fbr) * 0.5 + opt_size = np.floor(fbr - ftl).min() + opt_tl = (opt_center - opt_size * 0.5).astype(int) + opt_br = (opt_center + opt_size * 0.5).astype(int) + + # print('H, W', H, W) + # print('opt_center', opt_center) + # print('opt_size', opt_size) + # print('opt_tl', opt_tl) + # print('opt_br', opt_br) + + frames = frames[:, opt_tl[1]:opt_br[1], opt_tl[0]:opt_br[0], :].copy() + + # print('frames', frames.shape) + landmarks = landmarks - opt_tl + ratio = save_size / (opt_br - opt_tl) else: ratio = (save_size / W, save_size / H) landmarks = landmarks * ratio diff --git a/meme.py b/meme.py index 3903c39..4fc3335 100644 --- a/meme.py +++ b/meme.py @@ -220,7 +220,7 @@ class CropPortrait: def crop_portrait(self, image, face_toolkits): image_np = cv2.cvtColor((image[0] * 255).cpu().numpy().astype(np.uint8), cv2.COLOR_BGR2RGB) - image_np = cv2.resize(image_np, (512, 512)) + # image_np = cv2.resize(image_np, (512, 512)) # print(image_np.shape) face_toolkits['face_aligner'].reset_track() faces = face_toolkits['face_aligner'].forward(image_np)