How to use @azure/cognitiveservices-face - 2 common examples

To help you get started, we’ve selected a few @azure/cognitiveservices-face examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure-Samples / cognitive-services-quickstart-code / javascript / Face / FaceQuickstart.js View on Github external
let sourceClient = client // renaming to be relevent to this example

    // Your general Azure subscription ID is needed for this example only.
    // Since we are moving a person group from one region to another in the same
    // subscription, our source ID and target ID are the same.
    // Add your subscription ID (not to be confused with a subscription key) to your
    // environment variables. Find in the Azure portal on your Face overview page.
    let subscriptionID = process.env['AZURE_SUBSCRIPTION_ID']

    // Add a 2nd Face subscription key to your environment variables. Make sure the
    // 2nd set of key and endpoint is in the region or subscription you want to
    // transfer to.
    let credentials2 = new msRest.ApiKeyCredentials({
        inHeader: { 'Ocp-Apim-Subscription-Key': process.env['FACE_SUBSCRIPTION_KEY2'] }
    });
    let targetClient = new Face.FaceClient(credentials2, process.env['FACE_ENDPOINT2']);

    // Take the snapshot from your source region or Face subscription
    console.log('Taking the snapshot.')
    let takeOperationId = null
    await sourceClient.snapshot.take('PersonGroup', PERSON_GROUP_ID, [subscriptionID])
        .then((takeResponse) => {
            // Get the operation ID at the end of the response URL operation location
            takeOperationId = takeResponse.operationLocation.substring(takeResponse.operationLocation.lastIndexOf('/') + 1)
            console.log('Operation ID (take): ' + takeOperationId)
        }).catch((err) => {
            console.log(err)
            throw err
        })

    // With the operation ID, wait for the 'take' operation to complete
    let snapshotID = null
github Azure-Samples / cognitive-services-quickstart-code / javascript / Face / FaceQuickstart.js View on Github external
// An image with only one face
let singleFaceImageUrl = 'https://www.biography.com/.image/t_share/MTQ1MzAyNzYzOTgxNTE0NTEz/john-f-kennedy---mini-biography.jpg';
// An image with several faces
let groupImageUrl = 'http://www.historyplace.com/kennedy/president-family-portrait-closeup.jpg';
const IMAGE_BASE_URL = 'https://csdx.blob.core.windows.net/resources/Face/Images/'
// Person Group ID must be lower case, alphanumeric, with '-' and/or '_'.
const PERSON_GROUP_ID = 'my-unique-person-group'

/**
 * AUTHENTICATE
 * Used for all examples.
 */
// Set the FACE_SUBSCRIPTION_KEY in your environment variables with your subscription key as a value.
let credentials = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': process.env['FACE_SUBSCRIPTION_KEY'] } });
// Set FACE_REGION in your environment variables with its endpoint region (such as 'westus') as a value.
let client = new Face.FaceClient(credentials, process.env['FACE_ENDPOINT']);
/**
 * END - AUTHENTICATE
 */

async function main() {
    /**
     * DETECT FACES 
     * Detects the faces in the source image, then in the target image.
     */
    console.log("---------------------------------")
    console.log("DETECT FACES")

    // Detect a single face in an image. Returns a Promise.
    // NOTE: FaceDetectWithUrlOptionalParams.returnFaceId default value is true. See:
    // https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/cognitiveservices/cognitiveservices-face/src/models/index.ts#L891
    let singleDetectedFace = await client.face.detectWithUrl(singleFaceImageUrl)

@azure/cognitiveservices-face

FaceClient Library with typescript type definitions for node.js and browser.

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis

Popular @azure/cognitiveservices-face functions