Last active
May 27, 2021 00:54
-
-
Save symisc/6ecdea76ba0d33d73ea7f23cade0d216 to your computer and use it in GitHub Desktop.
Apply a blur filter automatically for each detected face using the PixLab Rest API (Python Sample)
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 | |
imgUrl = 'https://pixlab.io/images/m3.jpg' # Target picture we want to blur any face on | |
# Detect all human faces in a given image via /facedetect first and blur all of them later via /mogrify. | |
# https://pixlab.io/cmd?id=facedetect & https://pixlab.io/cmd?id=mogrify for additional information. | |
req = requests.get('https://api.pixlab.io/facedetect',params={ | |
'img': imgUrl, | |
'key':'PIXLAB_API_KEY', | |
}) | |
reply = req.json() | |
if reply['status'] != 200: | |
print (reply['error']) | |
exit(); | |
total = len(reply['faces']) # Total detected faces | |
print(str(total)+" faces were detected") | |
if total < 1: | |
# No faces were detected, exit immediately | |
exit() | |
# Pass the detected faces coordinates untouched to mogrify | |
coordinates = reply['faces'] | |
# Call mogrify via POST and pass the facial coordinates extracted earlier to blur the face(s) | |
req = requests.post('https://api.pixlab.io/mogrify',headers={'Content-Type':'application/json'},data=json.dumps({ | |
'img': imgUrl, | |
'key':'PIXLAB_API_KEY', | |
'cord': coordinates # The field of interest | |
})) | |
reply = req.json() | |
if reply['status'] != 200: | |
print (reply['error']) | |
else: | |
print ("Blurred Faces URL: "+ reply['ssl_link']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Detect all human faces in a given image via /facedetect first and blur all of them later via /mogrify.
https://pixlab.io/cmd?id=facedetect & https://pixlab.io/cmd?id=mogrify for additional information.