Home > Article > Backend Development > How does PHP call the FACE++ API to implement url face comparison (code example)
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('image_url1'=>$image1,'image_url2'=>$image2, 'api_key'=>"p-4a6YPMwxYTfzt9bvY8hw3CFF1f0rt4",'api_secret'=>"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:
Output:
Related recommendations:
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!