import cv2 import numpy as np # Load the original face image face_image = cv2.imread("path_to_face_image.jpg") # Suppose CAM_left and CAM_right are the CAM results for the eyes (each 32x64) CAM_left = cv2.imread("path_to_CAM_left.jpg") # or generated by your model CAM_right = cv2.imread("path_to_CAM_right.jpg") # or generated by your model # Example bounding boxes for the left and right eye left_eye_bbox = (x_left, y_left, width_left, height_left) right_eye_bbox = (x_right, y_right, width_right, height_right) # Resize CAM images if needed (they should be 32x64, but resize to match bbox size) CAM_left_resized = cv2.resize(CAM_left, (width_left, height_left)) CAM_right_resized = cv2.resize(CAM_right, (width_right, height_right)) # Create a copy of the face image to overlay the CAM results face_with_CAM = face_image.copy() # Overlay left eye CAM face_with_CAM[y_left : y_left + height_left, x_left : x_left + width_left] = CAM_left_resized # Overlay right eye CAM face_with_CAM[y_right : y_right + height_right, x_right : x_right + width_right] = CAM_right_resized # Save or display the result cv2.imwrite("face_with_CAM_overlay.jpg", face_with_CAM) cv2.imshow("Face with CAM Overlay", face_with_CAM) cv2.waitKey(0) cv2.destroyAllWindows()