A note on touching Microsoft's face recognition API in Python

A memo when writing your own code based on Official Documents

Environment (latest version at the time of writing)

Try

Install the required packages for the time being. You can do it with requests etc., but projectoxford is easier to write, so I adopted this!

$ pip install projectoxford

After that, prepare a subscription key and an image, and write a program.

face_api.py


import json, requests
from projectoxford import Client


client = Client('<your_subscription_key>')
res = {
    "url": "<image_url>",
    # or
    #'path': '</local/path/to/your_image>',
    'analyzesFaceLandmarks': True,
    'analyzesAge': True,
    'analyzesGender': True,
    'analyzesHeadPose': True,
}

result = client.face.detect(res)
print json.dumps(result, indent=4)

#Besides detect, groping, identify, verify,similar etc.

By the way, the result is like this.

$ python face_api.py

[
    {
        "attributes": {
            "gender": "male", 
            "age": 35, 
            "headPose": {
                "yaw": -7.7, 
                "roll": -5.7, 
                "pitch": 0.0
            }
        }, 
        "faceId": "************************", 
        "faceRectangle": {
            "width": 99, 
            "top": 80, 
            "height": 99, 
            "left": 201
        }, 
        "faceLandmarks": {
            "underLipTop": {
                "y": 160.5, 
                "x": 250.2
            }, 
            "noseTip": {
                "y": 129.7, 
                "x": 247.1
            }, 
            "upperLipBottom": {
                "y": 149.8, 
                "x": 249.5
            }, 
            "noseLeftAlarTop": {
                "y": 124.6, 
                "x": 240.2
            }, 
            "eyebrowLeftOuter": {
                "y": 107.8, 
                "x": 208.7
            }, 
            "eyeLeftBottom": {
                "y": 112.8, 
                "x": 226.7
            }, 
            "pupilLeft": {
                "y": 110.1, 
                "x": 228.2
            }, 
            "upperLipTop": {
                "y": 145.1, 
                "x": 249.1
            }, 
            "eyeLeftInner": {
                "y": 110.3, 
                "x": 234.0
            }, 
            "eyeRightInner": {
                "y": 107.0, 
                "x": 262.8
            }, 
            "eyeLeftTop": {
                "y": 108.5, 
                "x": 227.0
            }, 
            "mouthLeft": {
                "y": 155.5, 
                "x": 233.0
            }, 
            "noseRightAlarTop": {
                "y": 122.7, 
                "x": 258.3
            }, 
            "eyebrowRightInner": {
                "y": 101.1, 
                "x": 253.9
            }, 
            "noseLeftAlarOutTip": {
                "y": 133.7, 
                "x": 234.8
            }, 
            "noseRightAlarOutTip": {
                "y": 130.4, 
                "x": 263.9
            }, 
            "noseRootRight": {
                "y": 109.6, 
                "x": 253.9
            }, 
            "eyeLeftOuter": {
                "y": 112.4, 
                "x": 219.9
            }, 
            "underLipBottom": {
                "y": 166.9, 
                "x": 251.3
            }, 
            "eyeRightTop": {
                "y": 102.8, 
                "x": 269.8
            }, 
            "eyeRightOuter": {
                "y": 105.1, 
                "x": 276.1
            }, 
            "noseRootLeft": {
                "y": 110.9, 
                "x": 240.6
            }, 
            "eyebrowRightOuter": {
                "y": 96.1, 
                "x": 286.1
            }, 
            "eyeRightBottom": {
                "y": 107.0, 
                "x": 270.2
            }, 
            "eyebrowLeftInner": {
                "y": 104.1, 
                "x": 234.6
            }, 
            "mouthRight": {
                "y": 150.6, 
                "x": 272.5
            }, 
            "pupilRight": {
                "y": 104.4, 
                "x": 270.5
            }
        }
    }
]

Recommended Posts

A note on touching Microsoft's face recognition API in Python
Quickly try Microsoft's Face API in Python
A note on optimizing blackbox functions in Python
A note on handling variables in Python recursive functions
Serverless face recognition API made with Python
Note on encoding when LANG = C in Python
Data analysis in Python: A note about line_profiler
A simple Pub / Sub program note in Python
A memorandum for touching python Flask on heroku
Evernote API in Python
Speech recognition in Python
C API in Python 3
[LINE Messaging API] Create a rich menu in Python
Playing with a user-local artificial intelligence API in Python
Until drawing a 3D graph in Python on windows10
Things to note when initializing a list in Python
Write a log-scale histogram on the x-axis in python
A note on speeding up Python code with Numba
A note on the library implementation that explores hyperparameters using Bayesian optimization in Python
Hit Mastodon's API in Python
Take a screenshot in Python
A note on the default behavior of collate_fn in PyTorch
A note about hitting the Facebook API with the Python SDK
Create a function in Python
Create a dictionary in Python
Create a list in Python with all followers on twitter
Python Input Note in AtCoder
A note on how to load a virtual environment in PyCharm
[Note] Import of a file in the parent directory in Python
Make a bookmarklet in Python
Face detection summary in Python
Blender Python API in Houdini (Python 3)
Try face recognition with Python
Draw a heart in Python
A note about [python] __debug__
Create a Python environment for professionals in VS Code on Windows
A note on what you did to use Flycheck with Python
A game to go on an adventure in python interactive mode
Easy! Implement a Twitter bot that runs on Heroku in Python
Stream speech recognition using Google Cloud Speech gRPC API on python3 on Mac!
A note on using tab completion when running Python interactively on Windows
A class that summarizes frequently used methods in twitter api (python)
I made a Python wrapper library for docomo image recognition API.
Get the number of readers of a treatise on Mendeley in Python
Number recognition in images with Python
Building a Python environment on Mac
Maybe in a python (original title: Maybe in Python)
Write a binary search in Python
Getting the arXiv API in Python
[python] Manage functions in a list
Hit a command in Python (Windows)
[Note] Project Euler in Python (Problem 1-22)
Hit the Sesami API in Python
Python: A Note About Classes 1 "Abstract"
Create a Python environment on Mac (2017/4)
Draw a scatterplot matrix in python
A note about get_scorer in sklearn
ABC166 in Python A ~ C problem
Write A * (A-star) algorithm in Python
Create a binary file in Python
Create Gmail in Python without API