bisoye's picture
Update helper_fns.py
09abb1f verified
import io
import time
from PIL import Image
# Function to convert PIL image to binary
def pil_to_binary(img):
with io.BytesIO() as output:
img.save(output, format="PNG")
return output.getvalue()
def binary_to_pil(binary):
return Image.open(io.BytesIO(binary))
def crop_image(image_array, x, y, w, h):
return image_array[y: y + h, x: x + w]
def extract_faces(image_one, image_two, results):
image_one_results = results['facial_areas']['img1']
cropped_image_one = crop_image(image_one,
image_one_results['x'],
image_one_results['y'],
image_one_results['w'],
image_one_results['h'],)
image_two_results = results['facial_areas']['img2']
cropped_image_two = crop_image(image_two,
image_two_results['x'],
image_two_results['y'],
image_two_results['w'],
image_two_results['h'],)
return Image.fromarray(cropped_image_one).resize((480, 480)), Image.fromarray(cropped_image_two).resize((480, 480))