Skip to content

Instantly share code, notes, and snippets.

@connectwithprakash
Created February 1, 2020 20:02
Show Gist options
  • Select an option

  • Save connectwithprakash/1d64492210e85615dbb392596ea674f4 to your computer and use it in GitHub Desktop.

Select an option

Save connectwithprakash/1d64492210e85615dbb392596ea674f4 to your computer and use it in GitHub Desktop.
Cropping image of desired aspect ratio using windowing algorithm with center of window taken from face detection model.
detector = MTCNN() # face detection model
image = plt.imread(input_file_path)
results = detector.detect_faces(image)
confidences = [result['confidence'] for result in results]
index = np.argmax(confidences)
x1, y1, ww, hh = results[index]['box']
h, k = x1+ww//2, y1+hh//2
image = crop(image, (h, k), aspect_ratio)
plt.imsave(output_file_path, image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment