资讯 社区 文档
技术能力
语音技术
文字识别
人脸与人体
图像技术
语言与知识
视频技术

示例代码

var AipFaceClient = require("baidu-aip-sdk").face;
var APP_ID = "XXXXXXX";
var API_KEY = "YYYYYYYYY";
var SECRET_KEY = "ZZZZZZZZ";
//Initialize client
var client = new AipFaceClient(APP_ID, API_KEY, SECRET_KEY);

//check image quality
client.detect(face_image, 'BASE64', options).then(function (body) {
    if (body.error_code != 0) {
        console.log(JSON.stringify(body));
        return;
    }
    //The thresholds below can be adjusted according to the quality of the photo
    var face_angle = body.result.face_list[0].angle;
    var quality = body.result.face_list[0].quality;
    var baseAngleThreshold = 30;
    if (Math.abs(face_angle.yaw) > baseAngleThreshold ||
        Math.abs(face_angle.pitch) > baseAngleThreshold ||
        Math.abs(face_angle.roll) > baseAngleThreshold ||
        quality.occlusion.left_eye > 0.7 ||
        quality.occlusion.right_eye > 0.7 ||
        quality.occlusion.nose > 0.7 ||
        quality.occlusion.mouth > 0.7 ||
        quality.occlusion.left_cheek > 0.7 ||
        quality.occlusion.right_cheek > 0.7 ||
        quality.occlusion.chin_contour > 0.7) {
            console.log('Poor quality.');
            return;
    }

    //passed quality check; perform face search
    var group = 'test';
    var options = {"match_threshold": "70"};
    client.search(task.face_image, "BASE64", group, options).then(function (body) {
        if (body.error_code != 0) {
            console.log(JSON.stringify(body));
            return;
        }
        //If found, print the matched user (by default returns only the top match)
        console.log(JSON.stringify(body));
    }).catch(function(err) {
        console.log(err);
    });

}).catch(function(err) {
    console.log(err);
});