php调用百度人脸识别接口查询数据库人脸信息实现验证登录

博主在进行鼎食城毕业设计时,需要实现一个人脸识别登录功能,想到可以利用百度的人脸识别接口来完成,于是便去下载了百度的识别SDK,我用的是PHP,需要的的可以去下载其他版本,以下是识别效果:
在这里插入图片描述
在这里插入图片描述
用户在开始注册时需要上传一张自己的人脸照片,然后再登录时可以通过输入自己的用户名,然后上传自己拍照的图片通过数据库查询比对人脸,根据匹配相似的实现登录:
以下时识别代码:

<?php 
require_once 'AipFace.php';
require 'conn.php';
const APP_ID = '';
const API_KEY = '';
const SECRET_KEY = '';
if($_SERVER['REQUEST_METHOD']=='POST')
{    
$drivingLicence=$_FILES['drivingLicence']['tmp_name'];//临时地址
//echo $drivingLicence;


$id = $_POST['id'];
$result2 = mysql_query("SELECT * FROM user where userid='$id'");
					

// 你的 APPID AK SK


$client = new AipFace(APP_ID, API_KEY, SECRET_KEY);
$row=mysql_fetch_array($result2);
$result = $client->match(array(
    array(
        'image' => base64_encode(file_get_contents($row['face'])),
        'image_type' => 'BASE64',
    ),
    array(
        'image' => base64_encode(file_get_contents($drivingLicence)),
        'image_type' => 'BASE64',
    ),
));

//var_dump($result);


$score=$result['result']['score'];
if($score>90)
	echo "<center>匹配成功!正在为您登陆!";
else 
	echo "<center>匹配失败,请重新登录";
echo "<center>匹配相似度".$score;
}
?>

在这里插入图片描述
码字不易,给个赞呗

发布了60 篇原创文章 · 获赞 149 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/pengxiang1998/article/details/103945651