<head> <meta http-equiv = "Content-Type" content = "text/html; charset = utf-8" /> </head>
<style> body { text-align:left; height:500px; width:600px; top:50%; margin-top:130px; margin-left:550px; background-image:url(./imgs/back.jpg); background-position:center; background-repeat:repeat-y; } </style>
<input type = "button" value = "点击进入测试" onClick = "location='test.php' "/>
<form action="train.php" method="get"> <input type="text" name="trainDir"> <br> <input type="submit" name="submit" value="提交"> <input type="reset" name="reset" value = "重置"> </form>
$file = iconv("gb2312","UTF-8",$file);这一句才会得到结果的,要不就是空哦
function listDir($dir, &$names, &$img_urls) { if(is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if((is_dir($dir."/".$file)) && $file!="." && $file!="..") { //echo "<b><font color='red'>文件名:</font></b>",$file,"<br><hr>"; listDir($dir."/".$file."/"); } else { $file = iconv("gb2312","UTF-8",$file); if($file!="." && $file!="..") { //var_dump($file); $file_name = strstr($file, '.', true); //echo $file_name."<br>"; array_push($names, $file_name); array_push($img_urls, $dir."/".$file); } } } closedir($dh); } } }
$img_url = array(); $person_name = array(); $trainDir = $_GET["trainDir"]; listDir($trainDir, $person_name, $img_url); echo "从目录中我们得到了 ".sizeof($img_url)." 张图片".<br>;接着我们创建一个训练组oldpeople_qiaoxi。
$response = $facepp->execute('/group/delete', array('group_name' => 'oldpeople_qiaoxi')); $response = $facepp->execute('/group/create', array('group_name' => 'oldpeople_qiaoxi'));接着做循环,对每张图片检测人脸
$params['img'] = $img; $params['attribute'] = 'gender,age,race,smiling,glass,pose'; $response = $facepp->execute('/detection/detect',$params);从返回值$response得到face_id之后,创建一个person并将检测到的人脸加入这个类别person中。
$response = $facepp->execute('/person/delete', array('person_name' => $person_name[$i],'group_name' => 'oldpeople_qiaoxi')); $response = $facepp->execute('/person/create', array('person_name' => $person_name[$i],'group_name' => 'oldpeople_qiaoxi')); $response = $facepp->execute('/person/add_face', array('person_name' => $person_name[$i], 'face_id' => $face_id, 'group_name' => 'oldpeople_qiaoxi'));将所有图片都处理好之后,便可以训练模型了。
$response = $facepp->execute('/train/identify', array('group_name' => 'oldpeople_qiaoxi'));训练成功的话,结果如下:
$img_url = $_GET["testImgPath"];之后执行identify得到身份结果。
$response = $facepp->execute('/recognition/identify', array('group_name' => 'oldpeople_qiaoxi', 'img' => $img_url));这里采用了一个数组来进行中文名与英文名的对应,因为face++不支持中文名的图片,所以传给它的图片都是英文命名的,但是显示需要中文名,所以在这里进行映射。