def overlay(img, glasses, pos):
    sx = pos[0]
    ex = (pos[0] + glasses.shape[1])
    sy = pos[1]
    ey = (pos[1] + glasses.shape[0])
    if ((sx < 0) or (sy < 0) or (ex > img.shape[1]) or (ey > img.shape[0])):
        return
    img1 = img[sy:ey, sx:ex]
    img2 = glasses[:, :, 0:3]
    alpha = (1.0 - (glasses[:, :, 3] / 255.0))
    img1[(..., 0)] = ((img1[(..., 0)] * alpha) + (img2[(..., 0)] * (1.0 - alpha))).astype(np.uint8)
    img1[(..., 1)] = ((img1[(..., 1)] * alpha) + (img2[(..., 1)] * (1.0 - alpha))).astype(np.uint8)
    img1[(..., 2)] = ((img1[(..., 2)] * alpha) + (img2[(..., 2)] * (1.0 - alpha))).astype(np.uint8)
def overlay(img, glasses, pos):
    sx = pos[0]
    ex = (pos[0] + glasses.shape[1])
    sy = pos[1]
    ey = (pos[1] + glasses.shape[0])
    if ((sx < 0) or (sy < 0) or (ex > img.shape[1]) or (ey > img.shape[0])):
        return
    img1 = img[sy:ey, sx:ex]
    img2 = glasses[:, :, 0:3]
    alpha = (1.0 - (glasses[:, :, 3] / 255.0))
    img1[(..., 0)] = ((img1[(..., 0)] * alpha) + (img2[(..., 0)] * (1.0 - alpha))).astype(np.uint8)
    img1[(..., 1)] = ((img1[(..., 1)] * alpha) + (img2[(..., 1)] * (1.0 - alpha))).astype(np.uint8)
    img1[(..., 2)] = ((img1[(..., 2)] * alpha) + (img2[(..., 2)] * (1.0 - alpha))).astype(np.uint8)