nodejs 客户端拍照调用azure face api对比身份证照片进行验证
2017-11-18 20:46
423 查看
1. 注册azure账号获取azure face api key https://azure.microsoft.com/en-us/services/cognitive-services/face/ 2. javascript拍照
3. 使用获取face id api注册人脸,以及身份证照片(从数据库获得)
4. 调用find similar face api来对比两个人脸
实例代码:
var getFace = function (img,onsuccess) {
var faceApiUrl =
"https://southeastasia.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false";
return $.ajax({
url: faceApiUrl,
type: 'post',
data: JSON.stringify({
url: img
}),
headers: {
"Accept": "application/json",
"Content-Type": 'application/json',
"Ocp-Apim-Subscription-Key": subscribKey
},
dataType: 'text',
success: function (data) {
if (onsuccess != null) {
onsuccess(data);
}
}, fail: function (data) {
error("GOT 1st face failed.");
error(data);
console.error(data);
}
});
};
var compareFace = function(faceId1, faceId2, onsuccess) {
var faceApiUrl =
"https://southeastasia.api.cognitive.microsoft.com/face/v1.0/findsimilars";
return $.ajax({
url: faceApiUrl,
type: 'post',
data: JSON.stringify({
"faceId": faceId1,
"faceIds": [faceId2],
"maxNumOfCandidatesReturned": 1,
"mode": "matchFace"
}),
headers: {
"Accept": "application/json",
"Content-Type": 'application/json',
"Ocp-Apim-Subscription-Key": subscribKey
},
dataType: 'text',
success: function (data) {
if (onsuccess != null) {
onsuccess(data);
}
}, fail: function (data) {
error("compare face failed.");
error(data);
console.error(data);
}
});
}
var snapshot = function () {
var videoElement = document.querySelector(".remotevideo");
if (videoElement == null) {
videoElement = document.querySelector("#localVideo");
}
var canvasVideo = document.getElementById("pnlScreen");
var contextVideo = canvasVideo.getContext('2d');
contextVideo.drawImage(videoElement, 0, 0,600,480);
var base64 = document.getElementById("pnlScreen").toDataURL("image/png");
// console.log(base64);
//
$.ajax({
url: "your url",
type: 'post',
headers: {
"Content-Type": 'application/json'
},
data: JSON.stringify({ imgData: base64}),
success: function (data) {
if (data == "ok") {
getFace(image1,
function(data) {
debug("got 1st face JSON");
debug(data);
debug("got 1st face id");
var face1 = JSON.parse(data)[0].faceId;
debug(face1);
var face2 = "";
getFace(image2,
function(d) {
debug("got 2nd face JSON");
debug(d);
face2 = JSON.parse(d)[0].faceId;
debug("got 2nd face id");
debug(face2);
debug("comparing face");
compareFace(face1,
face2,
function(r) {
debug("compare success.");
var json = JSON.parse(r)[0];
showresult("matching confidence : " + json.confidence);
});
});
});
} else {
alert(data);
}
//alert(data);
}, fail: function (data) {
alert(data);
}
});
};
3. 使用获取face id api注册人脸,以及身份证照片(从数据库获得)
4. 调用find similar face api来对比两个人脸
实例代码:
var getFace = function (img,onsuccess) {
var faceApiUrl =
"https://southeastasia.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false";
return $.ajax({
url: faceApiUrl,
type: 'post',
data: JSON.stringify({
url: img
}),
headers: {
"Accept": "application/json",
"Content-Type": 'application/json',
"Ocp-Apim-Subscription-Key": subscribKey
},
dataType: 'text',
success: function (data) {
if (onsuccess != null) {
onsuccess(data);
}
}, fail: function (data) {
error("GOT 1st face failed.");
error(data);
console.error(data);
}
});
};
var compareFace = function(faceId1, faceId2, onsuccess) {
var faceApiUrl =
"https://southeastasia.api.cognitive.microsoft.com/face/v1.0/findsimilars";
return $.ajax({
url: faceApiUrl,
type: 'post',
data: JSON.stringify({
"faceId": faceId1,
"faceIds": [faceId2],
"maxNumOfCandidatesReturned": 1,
"mode": "matchFace"
}),
headers: {
"Accept": "application/json",
"Content-Type": 'application/json',
"Ocp-Apim-Subscription-Key": subscribKey
},
dataType: 'text',
success: function (data) {
if (onsuccess != null) {
onsuccess(data);
}
}, fail: function (data) {
error("compare face failed.");
error(data);
console.error(data);
}
});
}
var snapshot = function () {
var videoElement = document.querySelector(".remotevideo");
if (videoElement == null) {
videoElement = document.querySelector("#localVideo");
}
var canvasVideo = document.getElementById("pnlScreen");
var contextVideo = canvasVideo.getContext('2d');
contextVideo.drawImage(videoElement, 0, 0,600,480);
var base64 = document.getElementById("pnlScreen").toDataURL("image/png");
// console.log(base64);
//
$.ajax({
url: "your url",
type: 'post',
headers: {
"Content-Type": 'application/json'
},
data: JSON.stringify({ imgData: base64}),
success: function (data) {
if (data == "ok") {
getFace(image1,
function(data) {
debug("got 1st face JSON");
debug(data);
debug("got 1st face id");
var face1 = JSON.parse(data)[0].faceId;
debug(face1);
var face2 = "";
getFace(image2,
function(d) {
debug("got 2nd face JSON");
debug(d);
face2 = JSON.parse(d)[0].faceId;
debug("got 2nd face id");
debug(face2);
debug("comparing face");
compareFace(face1,
face2,
function(r) {
debug("compare success.");
var json = JSON.parse(r)[0];
showresult("matching confidence : " + json.confidence);
});
});
});
} else {
alert(data);
}
//alert(data);
}, fail: function (data) {
alert(data);
}
});
};
相关文章推荐
- 通过使用客户端证书调用 Web 服务以便在 ASP.NET Web 应用程序中进行身份验证
- android调用系统相机拍照与打开相册选择照片进行截取保存笔记
- 通过使用客户端证书调用 Web 服务进行身份验证{转}
- android 调用摄像头进行拍照,并对照片进行裁剪,然后显示。
- 如何调用手机自带的照相机APK进行拍照、录像并自动保存照片和录像
- 实现主流软件的调用系统相机拍照 取得照片 并进行加工
- 实现主流软件的调用系统相机拍照 取得照片 并进行加工
- 调用系统相机拍照,保存照片,调用系统裁剪API对照片处理,显示裁剪之后的照片
- 通过使用客户端证书调用 Web 服务进行身份验证(zz)
- CXF之使用jaxws API 发布服务与进行客户端调用
- CXF之使用CXF API 发布服务与进行客户端调用
- [置顶] android 调用系统相机进行拍照及照片的裁切
- unity调用摄像头进行拍照和保存照片
- python3.6+百度人脸识别API进行照片人脸对比
- Zookeeper系列三:Zookeeper客户端的使用(Zookeeper原生API如何进行调用、ZKClient、Curator)
- Android客户端之“微服私访”App的系统学习(八)调用系统摄像头拍照并管理照片并使用Okhttp上传文件至后台
- 通过使用客户端证书调用 Web 服务进行身份验证(zz)
- python调用pam模块进行linux用户验证
- 取客户端IP和MAC地址进行权限验证的一套体系
- android调用系统相机拍照保存照片并显示在当前界面