Skip to content

Commit

Permalink
Fix bug: imprecise back alignment when upscale_factor > 1 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
ToTheBeginning authored Sep 10, 2021
1 parent c158f31 commit a339560
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions facexlib/utils/face_restoration_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ def paste_faces_to_input_image(self, save_path=None, upsample_img=None):
assert len(self.restored_faces) == len(
self.inverse_affine_matrices), ('length of restored_faces and affine_matrices are different.')
for restored_face, inverse_affine in zip(self.restored_faces, self.inverse_affine_matrices):
# Add an offset to inverse affine matrix, for more precise back alignment
if self.upscale_factor > 1:
extra_offset = 0.5 * self.upscale_factor
else:
extra_offset = 0
inverse_affine[:, 2] += extra_offset
inv_restored = cv2.warpAffine(restored_face, inverse_affine, (w_up, h_up))
mask = np.ones(self.face_size, dtype=np.float32)
inv_mask = cv2.warpAffine(mask, inverse_affine, (w_up, h_up))
Expand Down

0 comments on commit a339560

Please sign in to comment.