import cv2
import numpy as np

# Load the source and target images
source_image_path = 'source image.png'
target_image_path = 'target image.jpg'

source_image = cv2.imread(source_image_path)
target_image = cv2.imread(target_image_path)

# We will assume the eye is roughly in the center of the source image and occupy a known fraction of it.
# These values might need to be adjusted depending on the source image.
source_center = (source_image.shape[1] // 2, source_image.shape[0] // 2)
eye_size = (source_image.shape[1] // 4, source_image.shape[0] // 4)

# Calculate the bounding box of the eye
eye_bbox = [source_center[0] - eye_size[0] // 2, source_center[1] - eye_size[1] // 2,
            source_center[0] + eye_size[0] // 2, source_center[1] + eye_size[1] // 2]

# Crop the eye from the source image
eye = source_image[eye_bbox[1]:eye_bbox[3], eye_bbox[0]:eye_bbox[2]]

# We will place the eye onto the palm of the hand in the target image.
# We assume that the palm is at the center of the target image and its size is known.
target_center = (target_image.shape[1] // 2, target_image.shape[0] // 2)
palm_size = (target_image.shape[1] // 3, target_image.shape[0] // 3)

# Calculate where to place the eye on the target image
placement_x = target_center[0] - eye.shape[1] // 2
placement_y = target_center[1] - eye.shape[0] // 2

# Create a mask for the eye
eye_mask = 255 * np.ones(eye.shape, eye.dtype)

# The seamlessClone function blends the source image onto the target image
result = cv2.seamlessClone(eye, target_image, eye_mask, (placement_x + eye.shape[1] // 2, placement_y + eye.shape[0] // 2), cv2.NORMAL_CLONE)

# Save the result
result_path = 'blended_image.jpg'
cv2.imwrite(result_path, result)

