diff --git a/packageD/pages/AI-test-skin/analyse/analyse.js b/packageD/pages/AI-test-skin/analyse/analyse.js index b15a485..1fe48f0 100644 --- a/packageD/pages/AI-test-skin/analyse/analyse.js +++ b/packageD/pages/AI-test-skin/analyse/analyse.js @@ -4,7 +4,6 @@ const request = app.request; const os = app.globalData; const setting = os.setting; const ut = require('../../../../utils/util'); -import { pluginGD } from '../../../ai_config/config' Page({ /** @@ -12,174 +11,171 @@ Page({ */ data: { iurl: setting.imghost, - per: 0, - timer: 0, - img: null, - sourceimg: null, - err_map: null, + per:0, + timer:0, + img:null, + sourceimg:null, + err_map:null, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { - //初始化美图测肤插件 - var plugin = requirePlugin('mtSkinSdk') - plugin.setConfig(pluginGD) - var th = this; - //设置错误码分析 - this.set_err_map(); - //进度条加载 - this.timer(); - //接口开始分析 - setTimeout(function () { - //th.analysis_img(); - //先检验一下图片 - th.mt_check(function () { - - }); - }, 800) + var th=this; + //设置错误码分析 + this.set_err_map(); + //进度条加载 + this.timer(); + //接口开始分析 + setTimeout(function () { + //th.analysis_img(); + //先检验一下图片 + th.img_check(function () { + + }); + },800) }, //定时器 - timer: function (func) { - var per = this.data.per + 5; - var th = this; - if (per < 96) { - th.setData({ per: per }); - setTimeout(function () { - th.timer(); - }, 400) - } + timer:function (func) { + var per=this.data.per+5; + var th=this; + if(per<96){ + th.setData({per:per}); + setTimeout(function () { + th.timer(); + },400) + } }, //错误码表 - set_err_map: function () { - var map = { - "2": "服务暂不可用", - "4": "集群超限额", - "6": "没有接口权限", - "17": "每天流量超限额", - "18": "QPS超限额", - "19": "请求总量超限额", - "100": "无效的access_token参数", - "110": "Access Token失效", - "111": " Access token过期", - "222001": "必要参数未传入", - "222002": "参数格式错误", - "222003": "参数格式错误", - "222004": "参数格式错误", - "222005": "参数格式错误", - "222006": "参数格式错误", - "222007": "参数格式错误", - "222008": "参数格式错误", - "222009": "参数格式错误", - "222010": "参数格式错误", - "222011": "参数格式错误", - "222012": "参数格式错误", - "222013": "参数格式错误", - "222014": "参数格式错误", - "222015": "参数格式错误", - "222016": "参数格式错误", - "222017": "参数格式错误", - "222018": "参数格式错误", - "222019": "参数格式错误", - "222020": "参数格式错误", - "222021": "参数格式错误", - "222022": "身份证号不符合要求,备注:中国大陆身份证号的每一位数字都有其生成规则,不可随意填写。", - "222023": "参数格式错误", - "222024": "参数格式错误", - "222025": "参数格式错误", - "222026": "参数格式错误", - "222027": "验证码长度错误(最小值大于最大值)", - "222028": "参数格式错误", - "222029": "参数格式错误", - "222030": "参数格式错误", - "222039": "参数格式错误", - "222200": "该接口需使用application/json的格式进行请求", - "222201": "服务端请求失败", - "222202": "图片中没有人脸", - "222203": "无法解析人脸", - "222204": "从图片的url下载图片失败", - "222205": "服务端请求失败", - "222206": "服务端请求失败", - "222207": "未找到匹配的用户", - "222208": "图片的数量错误", - "222209": "face token不存在", - "222210": "人脸库中用户下的人脸数目超过限制", - "222300": "人脸图片添加失败", - "222301": "获取人脸图片失败", - "222302": "服务端请求失败", - "222303": "获取人脸图片失败", - "222152": "人脸属性编辑,target参数错误", - "222514": "人脸属性编辑v2调用服务失败,请重试", - "223100": "操作的用户组不存在", - "223101": "该用户组已存在", - "223102": "找不到该用户", - "223103": "找不到该用户", - "223104": "group_list包含组数量过多", - "223105": "该人脸已存在", - "223106": "该人脸不存在", - "223107": "人脸库中人脸复制时源组与目标组的scene_type不同", - "223110": "uid_list包含数量过多", - "223111": "目标用户组不存在", - "223112": "quality_conf格式不正确", - "223113": "人脸有被遮挡", - "223114": "人脸模糊", - "223115": "人脸光照不好", - "223116": "人脸不完整", - "223117": "app_list包含app数量过多", - "223118": "质量控制项错误", - "223119": "活体控制项错误", - "223120": "活体检测未通过", - "223121": "质量检测未通过 左眼遮挡程度过高", - "223122": "质量检测未通过 右眼遮挡程度过高", - "223123": "质量检测未通过 左脸遮挡程度过高", - "223124": "质量检测未通过 右脸遮挡程度过高", - "223125": "质量检测未通过 下巴遮挡程度过高", - "223126": "质量检测未通过 鼻子遮挡程度过高", - "223127": "质量检测未通过 嘴巴遮挡程度过高", - "222901": "参数校验初始化失败", - "222902": "参数校验初始化失败", - "222903": "参数校验初始化失败", - "222904": "参数校验初始化失败", - "222905": "接口初始化失败", - "222906": "接口初始化失败", - "222907": "缓存处理失败", - "222908": "缓存处理失败", - "222909": "缓存处理失败", - "222910": "数据存储处理失败", - "222911": "数据存储处理失败", - "222912": "数据存储处理失败", - "222913": "接口初始化失败", - "222914": "接口初始化失败", - "222915": "后端服务连接失败", - "222916": "后端服务连接失败", - "222304": "图片尺寸太大", - "222305": "当前版本不支持图片存储", - "223128": "正在清理该用户组的数据", - "223136": "该组内存在关联图片,无法新建相同名称组", - "222361": "公安服务连接失败", - "222046": "参数格式错误", - "222101": "参数格式错误", - "222102": "参数格式错误", - "222307": "图片非法 鉴黄未通过", - "222308": "图片非法 含有政治敏感人物", - "222211": "人脸融合失败 模板图质量不合格", - "222212": "人脸融合失败", - "223129": "人脸未面向正前方(人脸的角度信息大于30度)", - "223130": "spoofing_control参数格式错误", - "223131": "合成图检测未通过", - "223201": "请求参数scene_type 格式错误", - "223202": "识别时请求的scene_type与group设置的scene_type不匹配", - } - this.setData({ err_map: map }); + set_err_map:function () { + var map={ + "2":"服务暂不可用", + "4":"集群超限额", + "6":"没有接口权限", + "17":"每天流量超限额", + "18":"QPS超限额", + "19":"请求总量超限额", + "100":"无效的access_token参数", + "110":"Access Token失效", + "111":" Access token过期", + "222001":"必要参数未传入", + "222002":"参数格式错误", + "222003":"参数格式错误", + "222004":"参数格式错误", + "222005":"参数格式错误", + "222006":"参数格式错误", + "222007":"参数格式错误", + "222008":"参数格式错误", + "222009":"参数格式错误", + "222010":"参数格式错误", + "222011":"参数格式错误", + "222012":"参数格式错误", + "222013":"参数格式错误", + "222014":"参数格式错误", + "222015":"参数格式错误", + "222016":"参数格式错误", + "222017":"参数格式错误", + "222018":"参数格式错误", + "222019":"参数格式错误", + "222020":"参数格式错误", + "222021":"参数格式错误", + "222022":"身份证号不符合要求,备注:中国大陆身份证号的每一位数字都有其生成规则,不可随意填写。", + "222023":"参数格式错误", + "222024":"参数格式错误", + "222025":"参数格式错误", + "222026":"参数格式错误", + "222027":"验证码长度错误(最小值大于最大值)", + "222028":"参数格式错误", + "222029":"参数格式错误", + "222030":"参数格式错误", + "222039":"参数格式错误", + "222200":"该接口需使用application/json的格式进行请求", + "222201":"服务端请求失败", + "222202":"图片中没有人脸", + "222203":"无法解析人脸", + "222204":"从图片的url下载图片失败", + "222205":"服务端请求失败", + "222206":"服务端请求失败", + "222207":"未找到匹配的用户", + "222208":"图片的数量错误", + "222209":"face token不存在", + "222210":"人脸库中用户下的人脸数目超过限制", + "222300":"人脸图片添加失败", + "222301":"获取人脸图片失败", + "222302":"服务端请求失败", + "222303":"获取人脸图片失败", + "222152":"人脸属性编辑,target参数错误", + "222514":"人脸属性编辑v2调用服务失败,请重试", + "223100":"操作的用户组不存在", + "223101":"该用户组已存在", + "223102":"找不到该用户", + "223103":"找不到该用户", + "223104":"group_list包含组数量过多", + "223105":"该人脸已存在", + "223106":"该人脸不存在", + "223107":"人脸库中人脸复制时源组与目标组的scene_type不同", + "223110":"uid_list包含数量过多", + "223111":"目标用户组不存在", + "223112":"quality_conf格式不正确", + "223113":"人脸有被遮挡", + "223114":"人脸模糊", + "223115":"人脸光照不好", + "223116":"人脸不完整", + "223117":"app_list包含app数量过多", + "223118":"质量控制项错误", + "223119":"活体控制项错误", + "223120":"活体检测未通过", + "223121":"质量检测未通过 左眼遮挡程度过高", + "223122":"质量检测未通过 右眼遮挡程度过高", + "223123":"质量检测未通过 左脸遮挡程度过高", + "223124":"质量检测未通过 右脸遮挡程度过高", + "223125":"质量检测未通过 下巴遮挡程度过高", + "223126":"质量检测未通过 鼻子遮挡程度过高", + "223127":"质量检测未通过 嘴巴遮挡程度过高", + "222901":"参数校验初始化失败", + "222902":"参数校验初始化失败", + "222903":"参数校验初始化失败", + "222904":"参数校验初始化失败", + "222905":"接口初始化失败", + "222906":"接口初始化失败", + "222907":"缓存处理失败", + "222908":"缓存处理失败", + "222909":"缓存处理失败", + "222910":"数据存储处理失败", + "222911":"数据存储处理失败", + "222912":"数据存储处理失败", + "222913":"接口初始化失败", + "222914":"接口初始化失败", + "222915":"后端服务连接失败", + "222916":"后端服务连接失败", + "222304":"图片尺寸太大", + "222305":"当前版本不支持图片存储", + "223128":"正在清理该用户组的数据", + "223136":"该组内存在关联图片,无法新建相同名称组", + "222361":"公安服务连接失败", + "222046":"参数格式错误", + "222101":"参数格式错误", + "222102":"参数格式错误", + "222307":"图片非法 鉴黄未通过", + "222308":"图片非法 含有政治敏感人物", + "222211":"人脸融合失败 模板图质量不合格", + "222212":"人脸融合失败", + "223129":"人脸未面向正前方(人脸的角度信息大于30度)", + "223130":"spoofing_control参数格式错误", + "223131":"合成图检测未通过", + "223201":"请求参数scene_type 格式错误", + "223202":"识别时请求的scene_type与group设置的scene_type不匹配", + } + this.setData({err_map:map}); }, /** * 生命周期函数--监听页面显示 */ - onShow: function () { }, + onShow: function (){ }, /** * 生命周期函数--监听页面隐藏 @@ -203,318 +199,159 @@ Page({ }, - mt_check() { - let img_info = getApp().globalData.skin_img_info; - var plugin = requirePlugin('mtSkinSdk'); - let th = this; - plugin.facePoseCorrect({ - path: img_info['path'], - size: img_info['size'], - success(res) { - console.log('=========姿态校正 成功==========') - console.log('姿态校正结果', res) - let analyse_info = res.data; - //检查闭眼情况 - if (analyse_info.analyse_info) { - //检查睁眼闭眼 - let { left, right } = analyse_info.analyse_info; - if (left !== 2 || right !== 2) { - var msg = "未闭眼拍照"; - th.go_error(msg); - return false; - } - } - //检查佩戴情况 - if (analyse_info.faceGlasses) { - let { none, normal, sunglasses } = analyse_info.faceGlasses; - if (normal > 0.8 || sunglasses > 0.8 || none < 0.1) { - var msg = "有佩戴眼镜"; - th.go_error(msg); - return false; - } - } - //检查框里情况 - if (analyse_info.faceOutDetect.outBound == 1) { - var msg = "未在取景框内"; - th.go_error(msg); - return false; - } - // if (analyse_info.facePoseEuler) { - // let { pitch, roll, yaw } = analyse_info.facePoseEuler; - // if (normal > 0.8 || sunglasses > 0.8 || none < 0.1) { - // var msg = "有佩戴眼镜"; - // th.go_error(msg); - // return false; - // } - // } - //检查环境情况 - if (analyse_info.faceQuality) { - let { bright, blur, compression } = analyse_info.faceQuality; - if (bright > 80) { - var msg = "亮度过亮"; - th.go_error(msg); - return false; - } - if (bright < 20 || blur < 20) { - var msg = "亮度过暗或图片过于模糊"; - th.go_error(msg); - return false; - } - } - //检查距离 - if (analyse_info.faceRatio < 0.2) { - var msg = "距离过远"; - th.go_error(msg); - return false; - } - if (analyse_info.faceRatio > 0.8) { - var msg = "距离过近"; - th.go_error(msg); - return false; - } - //检查遮挡物 - if (analyse_info.faceVisibility) { - var msg = ""; - let fail = Object.keys(analyse_info.faceVisibility).filter(key => { - return analyse_info.faceVisibility[key] <= 80; - }) - console.log('fail', fail); - switch (fail[0]) { - case "jaw": - msg = "下巴有遮挡"; - break; - case "leftcheek": - msg = "左脸有遮挡"; - break; - case "lefteye": - msg = "左眼有遮挡"; - break; - case "lefteyebrow": - msg = "左眉毛有遮挡"; - break; - case "mouse": - msg = "嘴巴有遮挡"; - break; - case "nose": - msg = "鼻子有遮挡"; - break; - case "rightcheek": - msg = "右脸有遮挡"; - break; - case "righteye": - msg = "右眼有遮挡"; - break; - case "rightyebrow": - msg = "右眉毛有遮挡"; - break; - } - if (msg) { - th.go_error(msg); - return false; - } - } - th.analyse_by_mtapi(img_info); - }, - fail(err) { - th.go_error('识别有误,请重试'); - return false; - } - }) - - }, - - analyse_by_mtapi(img_info) { - // let img_info = getApp().globalData.skin_img_info; - let th = this; - var plugin = requirePlugin('mtSkinSdk') - plugin.detectImage({ - path: img_info['path'], - size: img_info['size'], - success(res) { - console.log('=========用户传图片链接获取检测结果 成功==========') - console.log('检测结果', res); - let req_data = { - store_id: setting.stoid, - user_id: getApp().globalData.user_id, - img: getApp().globalData.face_img, - sourceimg: getApp().globalData.face_SourceImg, - addtime: ut.gettimestamp(), - resultjson: JSON.stringify(res.data.data), - detectjson: JSON.stringify(th.data.check_data) - } - //要保存一下分析的结果 - th.json_post("/api/weshop/face/storeSkinface/save", req_data, function (res) { - if (res.data.code == 0) { - let url = "/packageD/pages/AI-test-skin/success_result/success_result?id=" + res.data.data.id; //跳到分析页 - wx.redirectTo({ - url: url - }) - } else { - getApp().showWarning("保存失败"); - } - }) - }, - fail(err) { - console.error('=========用户传图片链接获取检测结果 失败==========') - console.log('error', err) - } - }) - }, - //检查图片有没有OK - img_check: function (func) { - var th = this; - var data = { + img_check:function (func) { + var th=this; + var data={ "appid": "25521854", "image": getApp().globalData.face_SourceImg, "face_field": "age,expression,face_shape,gender,glasses,landmark,landmark150,quality,eye_status,emotion,face_type,mask,spoofing", - "image_type": "URL", - "store_id":setting.stoid + "image_type": "URL" } //开始调用接口,进行对图片进行判断是否符合标准 - this.json_post("/api/weshop/baidubce/face/skindetect", data, function (res) { - if (res.data.code == 0) { + this.json_post("/api/weshop/baidubce/face/skindetect",data,function (res) { + if(res.data.code==0){ //检查的字段存储 - var check_data = th.data.check_data = res.data.data; - check_data = check_data.face_list[0]; + var check_data=th.data.check_data=res.data.data; + check_data=check_data.face_list[0]; console.log(check_data); //检查睁眼闭眼 - var eye_status = check_data.eye_status; - if (eye_status.left_eye > 0.1 || eye_status.right_eye > 0.1) { - var msg = "未闭眼拍照"; + var eye_status=check_data.eye_status; + if(eye_status.left_eye>0.1 || eye_status.right_eye>0.1) { + var msg="未闭眼拍照"; th.go_error(msg); return false; } //检查是不是有带眼镜 - if (check_data.glasses.type != 'none') { - var msg = "有佩戴眼镜"; + if(check_data.glasses.type!='none'){ + var msg="有佩戴眼镜"; th.go_error(msg); return false; } //检查头部的角度 - var angle = check_data.angle; - if (Math.abs(angle.Pitch) > 20) { - var msg = "头部的俯仰角度过大"; + var angle=check_data.angle; + if(Math.abs(angle.Pitch)>20) { + var msg="头部的俯仰角度过大"; th.go_error(msg); return false; } - if (Math.abs(angle.Roll) > 20) { - var msg = "头部的平面角度过大"; + if(Math.abs(angle.Roll)>20) { + var msg="头部的平面角度过大"; th.go_error(msg); return false; } - if (Math.abs(angle.Yaw) > 20) { - var msg = "头部的左右角度过大"; + if(Math.abs(angle.Yaw)>20) { + var msg="头部的左右角度过大"; th.go_error(msg); return false; } - var quality = check_data.quality; - if (quality.blur > 0.7) { - var msg = "图片模糊"; + var quality=check_data.quality; + if(quality.blur>0.7){ + var msg="图片模糊"; th.go_error(msg); return false; } //开始检查遮挡 - var occlusion = check_data.quality.occlusion; - if (occlusion.left_eye > 0.6) { - var msg = "左眼被遮挡"; + var occlusion=check_data.quality.occlusion; + if(occlusion.left_eye >0.6){ + var msg="左眼被遮挡"; th.go_error(msg); return false; } - if (occlusion.right_eye > 0.6) { - var msg = "右眼被遮挡"; + if(occlusion.right_eye>0.6){ + var msg="右眼被遮挡"; th.go_error(msg); return false; } - if (occlusion.nose > 0.7) { - var msg = "鼻子被遮挡"; + if(occlusion.nose>0.7){ + var msg="鼻子被遮挡"; th.go_error(msg); return false; } - if (occlusion.mouth > 0.7) { - var msg = "嘴巴被遮挡"; + if(occlusion.mouth>0.7){ + var msg="嘴巴被遮挡"; th.go_error(msg); return false; } - if (occlusion.left_cheek > 0.8) { - var msg = "左脸颊被遮挡"; + if(occlusion.left_cheek >0.8){ + var msg="左脸颊被遮挡"; th.go_error(msg); return false; } - if (occlusion.right_cheek > 0.8) { - var msg = "右脸颊被遮挡"; + if(occlusion.right_cheek >0.8){ + var msg="右脸颊被遮挡"; th.go_error(msg); return false; } - if (occlusion.chin_contour > 0.6) { - var msg = "下巴颊被遮挡"; + if(occlusion.chin_contour >0.6){ + var msg="下巴颊被遮挡"; th.go_error(msg); return false; } - if (quality.illumination < 40) { - var msg = "图像光照不足"; + if(quality.illumination<40){ + var msg="图像光照不足"; th.go_error(msg); return false; } - if (quality.completeness = 0) { - var msg = "人脸未显示完整"; + if(quality.completeness=0){ + var msg="人脸未显示完整"; th.go_error(msg); return false; } //-- 开始调用分析的接口 -- - var face_token = check_data.face_token; - var data = { + var face_token=check_data.face_token; + var data={ "image": face_token, "face_field": "color,smooth,acnespotmole,wrinkle,eyesattr,blackheadpore,skinface,skinquality", "image_type": "FACE_TOKEN" } th.analysis_img(data); - } else { - var msg = th.data.err_map[res.data.code + ""]; + }else{ + var msg=th.data.err_map[res.data.code+""]; th.go_error(msg); } }) }, - + //跳转到错误页面 - go_error: function (msg) { - let url = "/packageD/pages/AI-test-skin/fail_result/fail_result?msg=" + msg; //跳到分析页 + go_error:function (msg) { + let url = "/packageD/pages/AI-test-skin/fail_result/fail_result?msg="+msg; //跳到分析页 wx.redirectTo({ url: url }); }, - analysis_img: function (data) { - var th = this; + analysis_img:function (data) { + var th=this; //开始调用接口,进行分析 - this.json_post("/api/weshop/baidubce/face/skinAnalyze", data, function (res) { - if (res.data.code == 0) { - getApp().globalData.face_result = res.data.data; - var req_data = { - store_id: setting.stoid, - user_id: getApp().globalData.user_id, - img: getApp().globalData.face_img, - sourceimg: getApp().globalData.face_SourceImg, - addtime: ut.gettimestamp(), - resultjson: JSON.stringify(res.data.data), - detectjson: JSON.stringify(th.data.check_data) + this.json_post("/api/weshop/baidubce/face/skinAnalyze",data,function (res) { + if(res.data.code==0){ + getApp().globalData.face_result=res.data.data; + var req_data={ + store_id:setting.stoid, + user_id:getApp().globalData.user_id, + img:getApp().globalData.face_img, + sourceimg:getApp().globalData.face_SourceImg, + addtime:ut.gettimestamp(), + resultjson:JSON.stringify(res.data.data), + detectjson:JSON.stringify(th.data.check_data) } //要保存一下分析的结果 - th.json_post("/api/weshop/face/storeSkinface/save", req_data, function (res) { - if (res.data.code == 0) { - let url = "/packageD/pages/AI-test-skin/success_result/success_result?id=" + res.data.data.id; //跳到分析页 + th.json_post("/api/weshop/face/storeSkinface/save",req_data,function (res) { + if(res.data.code==0){ + let url = "/packageD/pages/AI-test-skin/success_result/success_result?id="+res.data.data.id; //跳到分析页 wx.redirectTo({ url: url }) - } else { + }else{ getApp().showWarning("保存失败"); } }) - } else { - var msg = th.data.err_map[res.data.code + ""]; - let url = "/packageD/pages/AI-test-skin/fail_result/fail_result?msg=" + msg; //跳到分析页 + }else{ + var msg=th.data.err_map[res.data.code+""]; + let url = "/packageD/pages/AI-test-skin/fail_result/fail_result?msg="+msg; //跳到分析页 wx.redirectTo({ - url: url + url: url }) } }) @@ -526,10 +363,10 @@ Page({ * @param {Object} succ //成功的回调 * @param {Object} fail //失败的回调 */ - json_post: function (url, data, succ, fail, mathod) { - var Mathod = "POST"; + json_post:function(url,data,succ,fail,mathod){ + var Mathod="POST"; if (mathod) Mathod = mathod; - if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; + if(url.indexOf("http")==-1) url=getApp().globalData.setting.url +url; var str = JSON.stringify(data); wx.request({ url: url, @@ -538,8 +375,8 @@ Page({ header: { 'content-type': 'application/json' },// 设置请求的 header - success: function (res) { succ(res); }, - fail: function (res) { fail(res); } + success: function (res) {succ(res); }, + fail:function(res){fail(res);} }) },