From 76204274aac31c02a361657c83538a99acf4612b Mon Sep 17 00:00:00 2001 From: lijianshe02 <48898730+lijianshe02@users.noreply.github.com> Date: Mon, 8 Mar 2021 18:53:16 +0800 Subject: [PATCH] return rectantle box instead of circle when there is only a single face (#226) --- ppgan/apps/first_order_predictor.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ppgan/apps/first_order_predictor.py b/ppgan/apps/first_order_predictor.py index 45c458111fa38..204615afb6fa2 100644 --- a/ppgan/apps/first_order_predictor.py +++ b/ppgan/apps/first_order_predictor.py @@ -154,6 +154,7 @@ def run(self, source_image, driving_video): results.append({'rec': rec, 'predict': predictions}) out_frame = [] + for i in range(len(driving_video)): frame = source_image.copy() for result in results: @@ -162,14 +163,17 @@ def run(self, source_image, driving_video): w = x2 - x1 out = result['predict'][i] * 255.0 out = cv2.resize(out.astype(np.uint8), (x2 - x1, y2 - y1)) - patch = np.zeros(frame.shape).astype('uint8') - patch[y1:y2, x1:x2] = out - mask = np.zeros(frame.shape[:2]).astype('uint8') - cx = int((x1 + x2) / 2) - cy = int((y1 + y2) / 2) - cv2.circle(mask, (cx, cy), math.ceil(h * self.ratio), - (255, 255, 255), -1, 8, 0) - frame = cv2.copyTo(patch, mask, frame) + if len(results) == 1: + frame[y1:y2, x1:x2] = out + else: + patch = np.zeros(frame.shape).astype('uint8') + patch[y1:y2, x1:x2] = out + mask = np.zeros(frame.shape[:2]).astype('uint8') + cx = int((x1 + x2) / 2) + cy = int((y1 + y2) / 2) + cv2.circle(mask, (cx, cy), math.ceil(h * self.ratio), + (255, 255, 255), -1, 8, 0) + frame = cv2.copyTo(patch, mask, frame) out_frame.append(frame) imageio.mimsave(os.path.join(self.output, self.filename),