在web登录人脸认证中,需要通过浏览器调用客户端电脑或手机的摄像头,再把获取的图像发送到服务端识别认证,这是通过人脸登录的基础。
本次测试采用html5调用客户端浏览器摄像头,获取图像发送到服务端认证
html5获取客户端摄像头画面,点击验证后,把客户端截屏数据进行base64编码,并模拟form提交数据,服务端获取post的form数据后,base64解码并存储在服务器临时图片文件,再把这个文件作为输入进行人脸识别。
1. checkface.html 发起认证
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
video {
border: 1px solid #ccc;
display: block;
margin: 0 0 20px 0;
float: left;
}
#canvas {
margin-top: 20px;
border: 1px solid #ccc;
display: block;
}
</style>
</head>
<body>
<video id="video" width="500" height="400" autoplay></video>
<canvas id="canvas" width="500" height="400"></canvas>
<button id="snap" style="width:500px;height:30px;font-size:24px;">拍照并人脸识别</button>
<script type="text/javascript">
var context = canvas.getContext("2d");
window.addEventListener("DOMContentLoaded", function() {
var canvas = document.getElementById("canvas");
var video = document.getElementById("video");
var videoObj = {"video" : true};
var errBack = function(error) {
console.log("Video capture error: ", error.code);
};
if (navigator.getUserMedia) {
navigator.getUserMedia(videoObj, function(stream) {