GithubHelp home page GithubHelp logo

faceapi's Introduction

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)

blurred_image

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()

blurred_image

faceapi's People

Contributors

humanova avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.