Update scripts/swap.py
Browse files- scripts/swap.py +9 -3
scripts/swap.py
CHANGED
|
@@ -22,7 +22,7 @@ def setup_models(execution_provider="cpu"):
|
|
| 22 |
|
| 23 |
if enhancer is None:
|
| 24 |
enhancer = GFPGANer(
|
| 25 |
-
model_path="gfpgan/weights/GFPGANv1.4.pth", #
|
| 26 |
upscale=1,
|
| 27 |
arch="clean",
|
| 28 |
channel_multiplier=2,
|
|
@@ -53,8 +53,14 @@ def run_swap(target_path, source_path, output_path, execution_provider="cpu", fr
|
|
| 53 |
target_img = swapper.get(target_img, face, source_face, paste_back=True)
|
| 54 |
|
| 55 |
if "face_enhancer" in frame_processors:
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
cv2.imwrite(output_path, target_img)
|
| 60 |
return True
|
|
|
|
| 22 |
|
| 23 |
if enhancer is None:
|
| 24 |
enhancer = GFPGANer(
|
| 25 |
+
model_path="gfpgan/weights/GFPGANv1.4.pth", # Modelo local
|
| 26 |
upscale=1,
|
| 27 |
arch="clean",
|
| 28 |
channel_multiplier=2,
|
|
|
|
| 53 |
target_img = swapper.get(target_img, face, source_face, paste_back=True)
|
| 54 |
|
| 55 |
if "face_enhancer" in frame_processors:
|
| 56 |
+
h, w = target_img.shape[:2] # Guardar dimensiones originales
|
| 57 |
+
_, _, enhanced_img = enhancer.enhance(
|
| 58 |
+
target_img,
|
| 59 |
+
has_aligned=False,
|
| 60 |
+
only_center_face=False
|
| 61 |
+
)
|
| 62 |
+
# Devolver imagen restaurada a tamaño original
|
| 63 |
+
target_img = cv2.resize(enhanced_img, (w, h), interpolation=cv2.INTER_CUBIC)
|
| 64 |
|
| 65 |
cv2.imwrite(output_path, target_img)
|
| 66 |
return True
|