You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
import cv2
|
|
import numpy as np
|
|
from tensorflow.keras.models import load_model
|
|
from tensorflow.keras.preprocessing.image import img_to_array, load_img
|
|
import matplotlib.pyplot as plt
|
|
from tensorflow.keras.losses import MeanSquaredError
|
|
|
|
def apply_aging_effect(model, image_path):
|
|
# Charger l'image
|
|
img = load_img(image_path, target_size=(512, 512)) # Augmenter la résolution des images
|
|
img_array = img_to_array(img) / 255.0
|
|
|
|
# Appliquer l'effet de vieillissement
|
|
predicted_img = model.predict(np.expand_dims(img_array, axis=0))
|
|
|
|
print(predicted_img)
|
|
print(type(predicted_img[0][0]))
|
|
print(f"Shape of predicted image: {predicted_img.shape}")
|
|
print(f"Predicted image values (min, max): {predicted_img.min()}, {predicted_img.max()}")
|
|
|
|
predicted_img = np.clip(predicted_img[0], 0, 1) # S'assurer que les valeurs sont entre 0 et 1
|
|
predicted_img = (predicted_img * 255).astype(np.uint8)
|
|
|
|
# Convertir en BGR pour OpenCV
|
|
predicted_img_bgr = cv2.cvtColor(predicted_img, cv2.COLOR_RGB2BGR)
|
|
|
|
return predicted_img_bgr
|
|
|
|
def main():
|
|
# Chemin vers le modèle et l'image
|
|
model_path = "face_aging_autoencoder.h5"
|
|
image_path = "visage.jpg"
|
|
output_path = "visage_aged.jpg"
|
|
|
|
# Charger le modèle
|
|
model = load_model(model_path, custom_objects={'mse': MeanSquaredError()})
|
|
print("Modèle chargé avec succès !")
|
|
|
|
# Appliquer l'effet de vieillissement
|
|
aged_image = apply_aging_effect(model, image_path)
|
|
|
|
# Sauvegarder l'image résultante
|
|
cv2.imwrite(output_path, aged_image)
|
|
print(f"Image vieillie sauvegardée sous {output_path}")
|
|
|
|
if __name__ == "__main__":
|
|
main() |