Last active
March 19, 2021 01:15
-
-
Save symisc/b6b9343969c52c0c919a08d1ad2630a6 to your computer and use it in GitHub Desktop.
Detect all human faces present in a given image via 'facedetect' and extract each one of them via 'crop' using the PixLab API - https://pixlab.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
# Detect all human faces present in a given image via 'facedetect' and extract each one of them via 'crop'. | |
# Target image: Feel free to change to whatever image holding as many human faces you want | |
img = 'http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg' | |
req = requests.get('https://api.pixlab.io/facedetect',params={ | |
'img': img, | |
'key':'PIXLAB_API_KEY', # Get your API Key from https://pixlab.io/dashboard | |
}) | |
reply = req.json() | |
if reply['status'] != 200: | |
print (reply['error']) | |
exit(); | |
total = len(reply['faces']) # Total detected faces | |
print(str(total)+" faces were detected") | |
# Extract each face via crop now | |
for face in reply['faces']: | |
req = requests.get('https://api.pixlab.io/crop',params={ | |
'img':img, | |
'key':'PIXLAB_API_KEY', # Get your API Key from https://pixlab.io/dashboard | |
'width': face['width'], | |
'height': face['height'], | |
'x': face['left'], | |
'y': face['top'] | |
}) | |
reply = req.json() | |
if reply['status'] != 200: | |
print (reply['error']) | |
else: | |
print ("Face #"+str(face['face_id'])+" location: "+ reply['link']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment