测试部分
php使用face++实现一个简单的人脸识别系统
流程
流程可以分为两部分,一部分是训练,一部分是测试。
关于如何使用face++提供的API可以看http://blog.csdn.net/jianjian1992/article/details/46640483
代码可在http://download.csdn.net/detail/jianjian1992/8866839免费下载。
起始界面
界面
如下所示,将使用说明进行了介绍,因为是初次使用,很多不太会,所以界面弄得比较简单,以能使用为第一目标。
实现细节
index.html是欢迎界面,记录一下几个小问题
中文的使用
在head部分加上字符集使用utf-8就好啦!
<meta http-equiv="Content-Type" content="text/html; charset = utf-8">
文字居中与背景设置
在html最前面加了个style,设置body的显示效果。
文字显示设置为居中,使用height,width加上margin-top,margin-left便可以设置body部分在页面中显示的地方啦。
背景则设置了图片url,以及居中显示。
<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>
按钮的页面跳转
onClick里面用location记录将要跳转的界面。
<input type="button" value="点击进入测试" onclick="location='test.php' ">
训练部分
包括两部分:
- startTrain.php用于输入训练目录,
- train.php用于将训练数据传到服务器,并将训练成功标记输出
startTrain.php
这一部分做得蛮挫的,查了下php选择文件夹,没有找到该怎么做,所以就用了个来输入目录。真是弱爆了啊
用了一个表单form来记录输入目录,提交表单之后则跳到train.php中进行真正的训练啦。

train.php
这一部分实现了两个功能:- 根据输入目录查找所有训练图片,并记录所有图片路径
- 将所有训练图片一一检测人脸,并将人脸加入到训练模型中
查找目录
php中查找目录中所有文件倒是挺方便的啊,listDir函数在dir.php中。
这个函数根据$dir目录名,将得到的所有文件名存入$names,所有文件路径名则存入$img_urls中。
注意的一点是,如果是中文文件名,则要加上
$file = iconv("gb2312","UTF-8",$file);
php中字符串的查找可以使用strstr函数,
比如下面的$file_name = strstr($file,'.',true)便是查找$file中‘.’的前面部分,如果是strstr($file,'.',false)则是'.'的后面部分。
动态数组的添加使用array_push就ok啦!
哦,不要忘记了关闭资源啊!有opendir($dir)那么就要有对应的closedir($dir)。
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 "文件名:",$file,"
"; listDir($dir."/".$file."/"); } else { $file = iconv("gb2312","UTF-8",$file); if($file!="." && $file!="..") { //var_dump($file); $file_name = strstr($file, '.', true); //echo $file_name."
"; array_push($names, $file_name); array_push($img_urls, $dir."/".$file); } } } closedir($dh); } }}
在train.php中使用如下代码便得到了训练用的所有图片的url啦。
$img_url = array();$person_name = array();$trainDir = $_GET["trainDir"];listDir($trainDir, $person_name, $img_url);echo "从目录中我们得到了 ".sizeof($img_url)." 张图片".<br>;
$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 = $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'));
测试部分
这个部分包括2个部分:
- test.php负责选择测试图片
- recognition.php负责将测试图片传到服务器并给出结果
test.php部分
显示如下:
选择文件部分用的是来做的,之后表单提交到recognition.php就好了。
recognition.php部分
首先得到图片的url。
$img_url = $_GET["testImgPath"];
$response = $facepp->execute('/recognition/identify', array('group_name' => 'oldpeople_qiaoxi', 'img' => $img_url));
$person_name = array("ami" => "艾米", "dongjian" => "张东健", "xiaowang" => "小王");

版权声明:本文为博主原创文章,未经博主允许不得转载。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

To learn more about open source, please visit: 51CTO Hongmeng Developer Community https://ost.51cto.com Running environment DAYU200:4.0.10.16SDK: 4.0.10.15IDE: 4.0.600 1. To create an application, click File- >newFile->CreateProgect. Select template: [OpenHarmony] EmptyAbility: Fill in the project name, shici, application package name com.nut.shici, and application storage location XXX (no Chinese, special characters, or spaces). CompileSDK10, Model: Stage. Device

How to convert php blob to file: 1. Create a php sample file; 2. Through "function blobToFile(blob) {return new File([blob], 'screenshot.png', { type: 'image/jpeg' })} ” method can be used to convert Blob to File.

Use Java's File.renameTo() function to rename files. In Java programming, we often need to rename files. Java provides the File class to handle file operations, and its renameTo() function can easily rename files. This article will introduce how to use Java's File.renameTo() function to rename files and provide corresponding code examples. The File.renameTo() function is a method of the File class.

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Use java's File.getParent() function to get the parent path of a file. In Java programming, we often need to operate files and folders. Sometimes, we need to get the parent path of a file, which is the path of the folder where the file is located. Java's File class provides the getParent() method to obtain the parent path of a file or folder. The File class is Java's abstract representation of files and folders. It provides a series of methods for operating files and folders. Among them, get

Use java's File.getParentFile() function to get the parent directory of a file. In Java programming, we often need to operate files and folders. When we need to get the parent directory of a file, we can use the File.getParentFile() function provided by Java. This article explains how to use this function and provides code examples. File class in Java is the main class used to operate files and folders. It provides many methods to obtain and manipulate file properties
