本篇文章給大家帶來的內容是關於PHP如何調用FACE++ API實現url人臉比較(程式碼範例),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。
output代碼(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代碼
<!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>
把php環境配好後把這兩個檔案放在根目錄下即可運行。
運行效果:
輸入:
輸出: