Home  >  Article  >  Backend Development  >  How does PHP call the FACE++ API to implement url face comparison (code example)

How does PHP call the FACE++ API to implement url face comparison (code example)

不言
不言Original
2018-08-29 15:55:013654browse

The content of this article is about how PHP calls the FACE API to implement url face comparison (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

output code (out.php).

<html>
<body bgcolor="#00ffff">
<center>
   <h1>Face Compare System</h1>
   </center>
   <center>
   <form action="face.php" method="post">
    URL1:<input type="text" name="URL_1">
    <br>
    <br>
    URL2:<input type="text" name="URL_2">
    <br>
    <br>
    <input type="submit" value="提交对比">
    </form>
    </center>
    </body>
    </html>

php code

<!DOCTYPE HTML>
<html>
<body bgcolor="#00ffff">
<center>
<?php
$image1=$_REQUEST["URL_1"];              //图片地址
$image2=$_REQUEST["URL_2"];
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api-cn.faceplusplus.com/facepp/v3/compare",     //输入URL
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => array(&#39;image_url1&#39;=>$image1,&#39;image_url2&#39;=>$image2, &#39;api_key&#39;=>"p-4a6YPMwxYTfzt9bvY8hw3CFF1f0rt4",&#39;api_secret&#39;=>"hpWzxBorFtEcSfjvs9jbywp5g4RX2ef8"),   //输入api_key和api_secret
    CURLOPT_HTTPHEADER => array("cache-control: no-cache",),
));
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    $arr=json_decode($response,true);    
    echo "人脸匹配度为";    
    echo $arr["confidence"],"%";

}
?>
</center>
</body>
</html>

After configuring the php environment, place these two files in the root directory. Runnable.

Running effect:
Input:
How does PHP call the FACE++ API to implement url face comparison (code example)

Output:
How does PHP call the FACE++ API to implement url face comparison (code example)

Related recommendations:

PHP uses the Face interface to develop the WeChat public platform face recognition system, face recognition system

Free face recognition api

The above is the detailed content of How does PHP call the FACE++ API to implement url face comparison (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn