1. 程式人生 > >微信小程式的人臉入庫

微信小程式的人臉入庫

思路

首先要判斷這張照片是否在檔案中,得到你的APP_ID,API_KEY,SECRET_KEY,然後呼叫AipFace,將照片寫成base64格式,再呼叫detect方法。如果正確會返回error_msg為SUCCESS。


程式碼

public function sdk(){
        $file = './Uploads/3.jpg';
        if(!file_exists($file)){
            die ("檔案不存在");
        }
        $dir = APP_PATH . '/face-sdk/';
        require_once $dir . "AipFace.php";
        $APP_ID = xxx;
        $API_KEY = xxx;
        $SECRET_KEY = xxx;

        $client = new \AipFace($APP_ID, $API_KEY, $SECRET_KEY);
        $image = file_get_contents($file);
        $image = base64_encode($image);
        // echo $image;
        // exit; 
        $imageType = "BASE64";

        $options = array();
        // $options["face_field"] = "age";
        $options["max_face_num"] = 6;
        // $options["face_type"] = "LIVE";

        $ret = $client->detect($image, $imageType,$options);
        print_r($ret);

    }