FaceAPI
Simple face detection API based on Flask and OpenCV. Currently uses SSDNet DNN model to detect faces.
Usage
API expects an image URL or base64 encoded image.
Sample JSON POST request to /api/v1/detect_url
.
{
"url" : "https://calvarychapeluniversity.com/wp-content/uploads/2011/04/CCU-GROUP41.jpg",
"threshold" : 0.7
}
Sample JSON POST request to /api/v1/detect
.
{
"img" : "c2RzZHN...2RzZA==",
"threshold" : 0.7
}
API Response Format
FaceAPI response includes boundry boxes of detected faces, total number of faces and detection time (in milliseconds).
{
"bboxes": [
{
"x1": 26,
"x2": 174,
"y1": 11,
"y2": 216
},
...
{
"x1": 481,
"x2": 635,
"y1": 247,
"y2": 450
}
],
"face_count": 6,
"success": true,
"time": 230
}
API Wrapper Example
Requesting and printing the response.
from faceDet import detectionURLRequest, cropFaces, blurFaces
import cv2
# stock photo including 7 clear faces
img = "https://cdn.psychologytoday.com/sites/default/files/styles/image-article_inline_full/public/field_blog_entry_teaser_image/people%20laughing_0.jpg"
# 1 - get API response
response, resp_time = detectionURLRequest(img, 0.7)
print("first bbox : ", response['bboxes'][0])
print("face count :", response['face_count'])
print("response time for first request(ms) :", resp_time)
first bbox : {'x1': 62, 'x2': 151, 'y1': 103, 'y2': 235}
face count : 7
response time for first request(ms) : 582
Using wrappers face blurer.
# 2 - get blurred image
blur = blurFaces(img, 0.7, is_url=True)
cv2.imshow('blurred img', blur)
Using wrappers face cropper.
# 3 - get cropped faces(img), face bboxes, and image itself
# iterate through and show faces
faces, bbox, image = cropFaces(img, 0.7)
i = 1
for face in faces:
cv2.imshow(str(i), face)
cv2.moveWindow(str(i), (i * 80) + 500, 500)
i+=1
# wait for key press to destroy the windows
cv2.waitKey(0)
cv2.destroyWindow()