Commit 1f11c563cc67f8c35e36653fa0c9bf52d76492b7

Authored by abson
1 parent 2bd2b7bb

测肤图片压缩

packageD/ai_config/config.js 0 → 100644
  1 +/*
  2 + * @Author: your name
  3 + * @Date: 2022-02-26 09:44:36
  4 + * @LastEditTime: 2022-02-26 09:48:10
  5 + * @LastEditors: your name
  6 + * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  7 + * @FilePath: \MShopWeApp\utils\ai_config\config.js
  8 + */
  9 +let pluginGD = {
  10 + app_id: 'f1WwFd7W1lduYRQaUpDVdvi3w9infpUwe1o',
  11 + app_secret: 'ICYb2dw1QDCguPuArQKi4EegwKfyFzDbdh',
  12 + plugin_name: 'mtSkinSdk',
  13 + redirect_url: '/packageD/pages/AI-test-skin/index/aiskin',
  14 + share_qrcode: 'https://titan-h5.meitu.com/webar/eve/mini_skin_sdk/demo/mini_qrcode.jpg',
  15 + wx_api: {
  16 + getFileSystemManager: wx.getFileSystemManager,
  17 + },
  18 +};
  19 +export {
  20 + pluginGD,
  21 +};
... ...
packageD/pages/AI-test-skin/analyse/analyse.js
... ... @@ -4,6 +4,7 @@ const request = app.request;
4 4 const os = app.globalData;
5 5 const setting = os.setting;
6 6 const ut = require('../../../../utils/util');
  7 +import { pluginGD } from '../../../ai_config/config'
7 8 Page({
8 9  
9 10 /**
... ... @@ -11,171 +12,171 @@ Page({
11 12 */
12 13 data: {
13 14 iurl: setting.imghost,
14   - per:0,
15   - timer:0,
16   - img:null,
17   - sourceimg:null,
18   - err_map:null,
  15 + per: 0,
  16 + timer: 0,
  17 + img: null,
  18 + sourceimg: null,
  19 + err_map: null,
  20 + skin_type: 0,
19 21 },
20 22  
21 23 /**
22 24 * 生命周期函数--监听页面加载
23 25 */
24 26 onLoad: function (options) {
25   - var th=this;
26   - //设置错误码分析
27   - this.set_err_map();
28   - //进度条加载
29   - this.timer();
30   - //接口开始分析
31   - setTimeout(function () {
32   - //th.analysis_img();
33   - //先检验一下图片
34   - th.img_check(function () {
35   -
36   - });
37   - },800)
  27 + var plugin = requirePlugin('mtSkinSdk')
  28 + plugin.setConfig(pluginGD)
  29 + var th = this;
  30 + //设置错误码分析
  31 + this.set_err_map();
  32 + //进度条加载
  33 + this.timer();
  34 + //接口开始分析
  35 + setTimeout(function () {
  36 + //先检验一下图片
  37 + th.data.skin_type ? th.img_check_mt() : th.img_check_bd();
  38 + }, 800)
38 39  
39 40 },
40 41 //定时器
41   - timer:function (func) {
42   - var per=this.data.per+5;
43   - var th=this;
44   - if(per<96){
45   - th.setData({per:per});
46   - setTimeout(function () {
47   - th.timer();
48   - },400)
49   - }
  42 + timer: function (func) {
  43 + var per = this.data.per + 5;
  44 + var th = this;
  45 + if (per < 96) {
  46 + th.setData({ per: per });
  47 + setTimeout(function () {
  48 + th.timer();
  49 + }, 400)
  50 + }
50 51 },
51 52  
52 53 //错误码表
53   - set_err_map:function () {
54   - var map={
55   - "2":"服务暂不可用",
56   - "4":"集群超限额",
57   - "6":"没有接口权限",
58   - "17":"每天流量超限额",
59   - "18":"QPS超限额",
60   - "19":"请求总量超限额",
61   - "100":"无效的access_token参数",
62   - "110":"Access Token失效",
63   - "111":" Access token过期",
64   - "222001":"必要参数未传入",
65   - "222002":"参数格式错误",
66   - "222003":"参数格式错误",
67   - "222004":"参数格式错误",
68   - "222005":"参数格式错误",
69   - "222006":"参数格式错误",
70   - "222007":"参数格式错误",
71   - "222008":"参数格式错误",
72   - "222009":"参数格式错误",
73   - "222010":"参数格式错误",
74   - "222011":"参数格式错误",
75   - "222012":"参数格式错误",
76   - "222013":"参数格式错误",
77   - "222014":"参数格式错误",
78   - "222015":"参数格式错误",
79   - "222016":"参数格式错误",
80   - "222017":"参数格式错误",
81   - "222018":"参数格式错误",
82   - "222019":"参数格式错误",
83   - "222020":"参数格式错误",
84   - "222021":"参数格式错误",
85   - "222022":"身份证号不符合要求,备注:中国大陆身份证号的每一位数字都有其生成规则,不可随意填写。",
86   - "222023":"参数格式错误",
87   - "222024":"参数格式错误",
88   - "222025":"参数格式错误",
89   - "222026":"参数格式错误",
90   - "222027":"验证码长度错误(最小值大于最大值)",
91   - "222028":"参数格式错误",
92   - "222029":"参数格式错误",
93   - "222030":"参数格式错误",
94   - "222039":"参数格式错误",
95   - "222200":"该接口需使用application/json的格式进行请求",
96   - "222201":"服务端请求失败",
97   - "222202":"图片中没有人脸",
98   - "222203":"无法解析人脸",
99   - "222204":"从图片的url下载图片失败",
100   - "222205":"服务端请求失败",
101   - "222206":"服务端请求失败",
102   - "222207":"未找到匹配的用户",
103   - "222208":"图片的数量错误",
104   - "222209":"face token不存在",
105   - "222210":"人脸库中用户下的人脸数目超过限制",
106   - "222300":"人脸图片添加失败",
107   - "222301":"获取人脸图片失败",
108   - "222302":"服务端请求失败",
109   - "222303":"获取人脸图片失败",
110   - "222152":"人脸属性编辑,target参数错误",
111   - "222514":"人脸属性编辑v2调用服务失败,请重试",
112   - "223100":"操作的用户组不存在",
113   - "223101":"该用户组已存在",
114   - "223102":"找不到该用户",
115   - "223103":"找不到该用户",
116   - "223104":"group_list包含组数量过多",
117   - "223105":"该人脸已存在",
118   - "223106":"该人脸不存在",
119   - "223107":"人脸库中人脸复制时源组与目标组的scene_type不同",
120   - "223110":"uid_list包含数量过多",
121   - "223111":"目标用户组不存在",
122   - "223112":"quality_conf格式不正确",
123   - "223113":"人脸有被遮挡",
124   - "223114":"人脸模糊",
125   - "223115":"人脸光照不好",
126   - "223116":"人脸不完整",
127   - "223117":"app_list包含app数量过多",
128   - "223118":"质量控制项错误",
129   - "223119":"活体控制项错误",
130   - "223120":"活体检测未通过",
131   - "223121":"质量检测未通过 左眼遮挡程度过高",
132   - "223122":"质量检测未通过 右眼遮挡程度过高",
133   - "223123":"质量检测未通过 左脸遮挡程度过高",
134   - "223124":"质量检测未通过 右脸遮挡程度过高",
135   - "223125":"质量检测未通过 下巴遮挡程度过高",
136   - "223126":"质量检测未通过 鼻子遮挡程度过高",
137   - "223127":"质量检测未通过 嘴巴遮挡程度过高",
138   - "222901":"参数校验初始化失败",
139   - "222902":"参数校验初始化失败",
140   - "222903":"参数校验初始化失败",
141   - "222904":"参数校验初始化失败",
142   - "222905":"接口初始化失败",
143   - "222906":"接口初始化失败",
144   - "222907":"缓存处理失败",
145   - "222908":"缓存处理失败",
146   - "222909":"缓存处理失败",
147   - "222910":"数据存储处理失败",
148   - "222911":"数据存储处理失败",
149   - "222912":"数据存储处理失败",
150   - "222913":"接口初始化失败",
151   - "222914":"接口初始化失败",
152   - "222915":"后端服务连接失败",
153   - "222916":"后端服务连接失败",
154   - "222304":"图片尺寸太大",
155   - "222305":"当前版本不支持图片存储",
156   - "223128":"正在清理该用户组的数据",
157   - "223136":"该组内存在关联图片,无法新建相同名称组",
158   - "222361":"公安服务连接失败",
159   - "222046":"参数格式错误",
160   - "222101":"参数格式错误",
161   - "222102":"参数格式错误",
162   - "222307":"图片非法 鉴黄未通过",
163   - "222308":"图片非法 含有政治敏感人物",
164   - "222211":"人脸融合失败 模板图质量不合格",
165   - "222212":"人脸融合失败",
166   - "223129":"人脸未面向正前方(人脸的角度信息大于30度)",
167   - "223130":"spoofing_control参数格式错误",
168   - "223131":"合成图检测未通过",
169   - "223201":"请求参数scene_type 格式错误",
170   - "223202":"识别时请求的scene_type与group设置的scene_type不匹配",
171   - }
172   - this.setData({err_map:map});
  54 + set_err_map: function () {
  55 + var map = {
  56 + "2": "服务暂不可用",
  57 + "4": "集群超限额",
  58 + "6": "没有接口权限",
  59 + "17": "每天流量超限额",
  60 + "18": "QPS超限额",
  61 + "19": "请求总量超限额",
  62 + "100": "无效的access_token参数",
  63 + "110": "Access Token失效",
  64 + "111": " Access token过期",
  65 + "222001": "必要参数未传入",
  66 + "222002": "参数格式错误",
  67 + "222003": "参数格式错误",
  68 + "222004": "参数格式错误",
  69 + "222005": "参数格式错误",
  70 + "222006": "参数格式错误",
  71 + "222007": "参数格式错误",
  72 + "222008": "参数格式错误",
  73 + "222009": "参数格式错误",
  74 + "222010": "参数格式错误",
  75 + "222011": "参数格式错误",
  76 + "222012": "参数格式错误",
  77 + "222013": "参数格式错误",
  78 + "222014": "参数格式错误",
  79 + "222015": "参数格式错误",
  80 + "222016": "参数格式错误",
  81 + "222017": "参数格式错误",
  82 + "222018": "参数格式错误",
  83 + "222019": "参数格式错误",
  84 + "222020": "参数格式错误",
  85 + "222021": "参数格式错误",
  86 + "222022": "身份证号不符合要求,备注:中国大陆身份证号的每一位数字都有其生成规则,不可随意填写。",
  87 + "222023": "参数格式错误",
  88 + "222024": "参数格式错误",
  89 + "222025": "参数格式错误",
  90 + "222026": "参数格式错误",
  91 + "222027": "验证码长度错误(最小值大于最大值)",
  92 + "222028": "参数格式错误",
  93 + "222029": "参数格式错误",
  94 + "222030": "参数格式错误",
  95 + "222039": "参数格式错误",
  96 + "222200": "该接口需使用application/json的格式进行请求",
  97 + "222201": "服务端请求失败",
  98 + "222202": "未识别到单个人脸",//未识别到单个人脸
  99 + "222203": "无法解析人脸",
  100 + "222204": "从图片的url下载图片失败",
  101 + "222205": "服务端请求失败",
  102 + "222206": "服务端请求失败",
  103 + "222207": "未找到匹配的用户",
  104 + "222208": "图片的数量错误",
  105 + "222209": "face token不存在",
  106 + "222210": "人脸库中用户下的人脸数目超过限制",
  107 + "222300": "人脸图片添加失败",
  108 + "222301": "获取人脸图片失败",
  109 + "222302": "服务端请求失败",
  110 + "222303": "获取人脸图片失败",
  111 + "222152": "人脸属性编辑,target参数错误",
  112 + "222514": "人脸属性编辑v2调用服务失败,请重试",
  113 + "223100": "操作的用户组不存在",
  114 + "223101": "该用户组已存在",
  115 + "223102": "找不到该用户",
  116 + "223103": "找不到该用户",
  117 + "223104": "group_list包含组数量过多",
  118 + "223105": "该人脸已存在",
  119 + "223106": "该人脸不存在",
  120 + "223107": "人脸库中人脸复制时源组与目标组的scene_type不同",
  121 + "223110": "uid_list包含数量过多",
  122 + "223111": "目标用户组不存在",
  123 + "223112": "quality_conf格式不正确",
  124 + "223113": "人脸有被遮挡",
  125 + "223114": "人脸模糊",
  126 + "223115": "人脸光照不好",
  127 + "223116": "人脸不完整",
  128 + "223117": "app_list包含app数量过多",
  129 + "223118": "质量控制项错误",
  130 + "223119": "活体控制项错误",
  131 + "223120": "活体检测未通过",
  132 + "223121": "质量检测未通过 左眼遮挡程度过高",
  133 + "223122": "质量检测未通过 右眼遮挡程度过高",
  134 + "223123": "质量检测未通过 左脸遮挡程度过高",
  135 + "223124": "质量检测未通过 右脸遮挡程度过高",
  136 + "223125": "质量检测未通过 下巴遮挡程度过高",
  137 + "223126": "质量检测未通过 鼻子遮挡程度过高",
  138 + "223127": "质量检测未通过 嘴巴遮挡程度过高",
  139 + "222901": "参数校验初始化失败",
  140 + "222902": "参数校验初始化失败",
  141 + "222903": "参数校验初始化失败",
  142 + "222904": "参数校验初始化失败",
  143 + "222905": "接口初始化失败",
  144 + "222906": "接口初始化失败",
  145 + "222907": "缓存处理失败",
  146 + "222908": "缓存处理失败",
  147 + "222909": "缓存处理失败",
  148 + "222910": "数据存储处理失败",
  149 + "222911": "数据存储处理失败",
  150 + "222912": "数据存储处理失败",
  151 + "222913": "接口初始化失败",
  152 + "222914": "接口初始化失败",
  153 + "222915": "后端服务连接失败",
  154 + "222916": "后端服务连接失败",
  155 + "222304": "图片尺寸太大",
  156 + "222305": "当前版本不支持图片存储",
  157 + "223128": "正在清理该用户组的数据",
  158 + "223136": "该组内存在关联图片,无法新建相同名称组",
  159 + "222361": "公安服务连接失败",
  160 + "222046": "参数格式错误",
  161 + "222101": "参数格式错误",
  162 + "222102": "参数格式错误",
  163 + "222307": "图片非法 鉴黄未通过",
  164 + "222308": "图片非法 含有政治敏感人物",
  165 + "222211": "人脸融合失败 模板图质量不合格",
  166 + "222212": "人脸融合失败",
  167 + "223129": "人脸未面向正前方(人脸的角度信息大于30度)",
  168 + "223130": "spoofing_control参数格式错误",
  169 + "223131": "合成图检测未通过",
  170 + "223201": "请求参数scene_type 格式错误",
  171 + "223202": "识别时请求的scene_type与group设置的scene_type不匹配",
  172 + }
  173 + this.setData({ err_map: map });
173 174 },
174 175  
175 176 /**
176 177 * 生命周期函数--监听页面显示
177 178 */
178   - onShow: function (){ },
  179 + onShow: function () { },
179 180  
180 181 /**
181 182 * 生命周期函数--监听页面隐藏
... ... @@ -199,163 +200,359 @@ Page({
199 200  
200 201 },
201 202  
202   - //检查图片有没有OK
203   - img_check:function (func) {
204   - var th=this;
205   - var data={
  203 + //检查图片有没有OK 百度
  204 + img_check_bd: function (func) {
  205 + var th = this;
  206 + var data = {
206 207 "appid": "25521854",
207 208 "image": getApp().globalData.face_SourceImg,
208 209 "face_field": "age,expression,face_shape,gender,glasses,landmark,landmark150,quality,eye_status,emotion,face_type,mask,spoofing",
209 210 "image_type": "URL"
210 211 }
211   - //开始调用接口,进行对图片进行判断是否符合标准
212   - this.json_post("/api/weshop/baidubce/face/skindetect",data,function (res) {
213   - if(res.data.code==0){
  212 + //开始调用百度接口,进行对图片进行判断是否符合标准
  213 + this.json_post("/api/weshop/baidubce/face/skindetect", data, function (res) {
  214 + if (res.data.code == 0) {
214 215 //检查的字段存储
215   - var check_data=th.data.check_data=res.data.data;
216   - check_data=check_data.face_list[0];
  216 + var check_data = th.data.check_data = res.data.data;
  217 + check_data = check_data.face_list[0];
  218 + let fail_result = new Array();
217 219 console.log(check_data);
218 220 //检查睁眼闭眼
219   - var eye_status=check_data.eye_status;
220   - if(eye_status.left_eye>0.1 || eye_status.right_eye>0.1) {
221   - var msg="未闭眼拍照";
222   - th.go_error(msg);
223   - return false;
  221 + var eye_status = check_data.eye_status;
  222 + if (eye_status.left_eye > 0.1 || eye_status.right_eye > 0.1) {
  223 + // var msg = "未闭眼拍照";
  224 + // th.go_error(msg);
  225 + // return false;
  226 + fail_result.push({
  227 + type: 1,
  228 + reason: "未闭眼拍摄"
  229 + })
224 230 }
225 231 //检查是不是有带眼镜
226   - if(check_data.glasses.type!='none'){
227   - var msg="有佩戴眼镜";
228   - th.go_error(msg);
229   - return false;
230   - }
231   - //检查头部的角度
232   - var angle=check_data.angle;
233   - if(Math.abs(angle.Pitch)>20) {
234   - var msg="头部的俯仰角度过大";
235   - th.go_error(msg);
236   - return false;
  232 + if (check_data.glasses.type != 'none') {
  233 + // var msg = "有佩戴眼镜";
  234 + // th.go_error(msg);
  235 + // return false;
  236 + fail_result.push({
  237 + type: 2,
  238 + reason: "未摘下眼镜拍摄"
  239 + })
237 240 }
238   - if(Math.abs(angle.Roll)>20) {
239   - var msg="头部的平面角度过大";
240   - th.go_error(msg);
241   - return false;
  241 + var quality = check_data.quality;
  242 + //检查框里人脸情况
  243 + if (quality.completeness = 0) {
  244 + // var msg = "人脸未显示完整";
  245 + // th.go_error(msg);
  246 + // return false;
  247 + fail_result.push({
  248 + type: 3,
  249 + reason: "未识别到单个人脸"
  250 + })
242 251 }
243   - if(Math.abs(angle.Yaw)>20) {
244   - var msg="头部的左右角度过大";
245   - th.go_error(msg);
246   - return false;
247   - }
248   - var quality=check_data.quality;
249   - if(quality.blur>0.7){
250   - var msg="图片模糊";
251   - th.go_error(msg);
252   - return false;
  252 + //检查环境情况
  253 + if (quality.blur > 0.7 || quality.illumination < 40) {
  254 + // var msg = "图片模糊";
  255 + // th.go_error(msg);
  256 + // return false;
  257 + fail_result.push({
  258 + type: 4,
  259 + reason: "图片质量不佳"
  260 + })
253 261 }
  262 +
  263 + // if (Math.abs(angle.Roll) > 20) {
  264 + // var msg = "头部的平面角度过大";
  265 + // th.go_error(msg);
  266 + // return false;
  267 + // }
  268 + // if (Math.abs(angle.Yaw) > 20) {
  269 + // var msg = "头部的左右角度过大";
  270 + // th.go_error(msg);
  271 + // return false;
  272 + // }
  273 +
254 274 //开始检查遮挡
255   - var occlusion=check_data.quality.occlusion;
256   - if(occlusion.left_eye >0.6){
257   - var msg="左眼被遮挡";
258   - th.go_error(msg);
259   - return false;
  275 + var zhe_dnag = 0;
  276 + var occlusion = check_data.quality.occlusion;
  277 + if (occlusion.left_eye > 0.6) {
  278 + // var msg = "左眼被遮挡";
  279 + // th.go_error(msg);
  280 + // return false;
  281 + zhe_dnag = 1;
260 282 }
261   - if(occlusion.right_eye>0.6){
262   - var msg="右眼被遮挡";
263   - th.go_error(msg);
264   - return false;
  283 + if (occlusion.right_eye > 0.6) {
  284 + // var msg = "右眼被遮挡";
  285 + // th.go_error(msg);
  286 + // return false;
  287 + zhe_dnag = 1;
265 288 }
266   - if(occlusion.nose>0.7){
267   - var msg="鼻子被遮挡";
268   - th.go_error(msg);
269   - return false;
  289 + if (occlusion.nose > 0.7) {
  290 + // var msg = "鼻子被遮挡";
  291 + // th.go_error(msg);
  292 + // return false;
  293 + zhe_dnag = 1;
270 294 }
271   - if(occlusion.mouth>0.7){
272   - var msg="嘴巴被遮挡";
273   - th.go_error(msg);
274   - return false;
  295 + if (occlusion.mouth > 0.7) {
  296 + // var msg = "嘴巴被遮挡";
  297 + // th.go_error(msg);
  298 + // return false;
  299 + zhe_dnag = 1;
275 300 }
276   - if(occlusion.left_cheek >0.8){
277   - var msg="左脸颊被遮挡";
278   - th.go_error(msg);
279   - return false;
  301 + if (occlusion.left_cheek > 0.8) {
  302 + // var msg = "左脸颊被遮挡";
  303 + // th.go_error(msg);
  304 + // return false;
  305 + zhe_dnag = 1;
280 306 }
281   - if(occlusion.right_cheek >0.8){
282   - var msg="右脸颊被遮挡";
283   - th.go_error(msg);
284   - return false;
  307 + if (occlusion.right_cheek > 0.8) {
  308 + // var msg = "右脸颊被遮挡";
  309 + // th.go_error(msg);
  310 + // return false;
  311 + zhe_dnag = 1;
285 312 }
286   - if(occlusion.chin_contour >0.6){
287   - var msg="下巴颊被遮挡";
288   - th.go_error(msg);
289   - return false;
  313 + if (occlusion.chin_contour > 0.6) {
  314 + // var msg = "下巴颊被遮挡";
  315 + // th.go_error(msg);
  316 + // return false;
  317 + zhe_dnag = 1;
290 318 }
291   - if(quality.illumination<40){
292   - var msg="图像光照不足";
293   - th.go_error(msg);
294   - return false;
  319 + if (zhe_dnag) {
  320 + fail_result.push({
  321 + type: 7,
  322 + reason: "脸部有遮挡物"
  323 + })
295 324 }
296   - if(quality.completeness=0){
297   - var msg="人脸未显示完整";
298   - th.go_error(msg);
  325 + //检查头部的角度
  326 + var angle = check_data.angle;
  327 + if (Math.abs(angle.Pitch) > 20 || Math.abs(angle.Roll) > 20 || Math.abs(angle.Yaw) > 20) {
  328 + // var msg = "头部的俯仰角度过大";
  329 + // th.go_error(msg);
  330 + // return false;
  331 + fail_result.push({
  332 + type: 8,
  333 + reason: "未保持正脸拍摄"
  334 + })
  335 + }
  336 + // if (quality.illumination < 40) {
  337 + // var msg = "图像光照不足";
  338 + // th.go_error(msg);
  339 + // return false;
  340 + // }
  341 + if (fail_result.length > 0) {
  342 + fail_result = JSON.stringify(fail_result);
  343 + th.go_error(fail_result);
299 344 return false;
300 345 }
301 346 //-- 开始调用分析的接口 --
302   - var face_token=check_data.face_token;
303   - var data={
  347 + var face_token = check_data.face_token;
  348 + var data = {
304 349 "image": face_token,
305 350 "face_field": "color,smooth,acnespotmole,wrinkle,eyesattr,blackheadpore,skinface,skinquality",
306 351 "image_type": "FACE_TOKEN"
307 352 }
308   - th.analysis_img(data);
309   - }else{
310   - var msg=th.data.err_map[res.data.code+""];
311   - th.go_error(msg);
  353 + th.analyse_by_bd(data);
  354 + } else {
  355 + var msg = th.data.err_map[res.data.code + ""];
  356 + th.go_error1(msg);
312 357 }
313 358 })
314 359 },
315   -
316   - //跳转到错误页面
317   - go_error:function (msg) {
318   - let url = "/packageD/pages/AI-test-skin/fail_result/fail_result?msg="+msg; //跳到分析页
319   - wx.redirectTo({
320   - url: url
321   - });
322   - },
  360 + //检查图片有没有OK 美图
  361 + img_check_mt() {
  362 + let img_info = getApp().globalData.skin_img_info;
  363 + var plugin = requirePlugin('mtSkinSdk');
  364 + console.log('plugin');
  365 + let th = this;
  366 + plugin.facePoseCorrect({
  367 + path: img_info['path'],
  368 + size: img_info['size'],
  369 + success(res) {
  370 + console.log('=========姿态校正 成功==========')
  371 + console.log('姿态校正结果', res)
  372 + let fail_result = new Array();
  373 + let analyse_info = res.data;
  374 + //检查闭眼情况
  375 + if (analyse_info.analyse_info) {
  376 + //检查睁眼闭眼
  377 + let { left, right } = analyse_info.analyse_info;
  378 + if (left !== 2 && right !== 2) {
  379 + fail_result.push({
  380 + type: 1,
  381 + reason: "未闭眼拍摄"
  382 + })
  383 + }
  384 + }
  385 + //检查佩戴情况
  386 + if (analyse_info.faceGlasses) {
  387 + let { none, normal, sunglasses } = analyse_info.faceGlasses;
  388 + if (normal > 0.8 || sunglasses > 0.8 || none < 0.1) {
  389 + fail_result.push({
  390 + type: 2,
  391 + reason: "未摘下眼镜拍摄"
  392 + })
  393 + }
  394 + }
  395 + //检查框里人脸情况
  396 + if (analyse_info.faceOutDetect.outBound == 1) {
  397 + fail_result.push({
  398 + type: 3,
  399 + reason: "未识别到单个人脸"
  400 + })
  401 + }
323 402  
324   - analysis_img:function (data) {
325   - var th=this;
  403 + //检查环境情况
  404 + if (analyse_info.faceQuality) {
  405 + let { bright, blur } = analyse_info.faceQuality;
  406 + if (bright > 80 || bright < 20 || blur < 20) {
  407 + fail_result.push({
  408 + type: 4,
  409 + reason: "质量检测未通过"
  410 + })
  411 + }
  412 + }
  413 + //检查距离
  414 + if (analyse_info.faceRatio < 0.2) {
  415 + fail_result.push({
  416 + type: 5,
  417 + reason: "脸部与摄像头距离过远"
  418 + })
  419 + }
  420 + if (analyse_info.faceRatio > 0.8) {
  421 + fail_result.push({
  422 + type: 6,
  423 + reason: "脸部与摄像头距离过近"
  424 + })
  425 +
  426 + }
  427 + //检查遮挡物
  428 + if (analyse_info.faceVisibility) {
  429 + let fail = Object.keys(analyse_info.faceVisibility).filter(key => {
  430 + return analyse_info.faceVisibility[key] <= 80;
  431 + })
  432 + console.log('fail', fail);
  433 + if (fail.length > 0) {
  434 + fail_result.push({
  435 + type: 7,
  436 + reason: "脸部有遮挡物"
  437 + })
  438 + }
  439 + }
  440 + if (analyse_info.facePoseEuler) {
  441 + let { pitch, roll, yaw } = analyse_info.facePoseEuler;
  442 + if (pitch > 20 || roll > 20 || yaw > 20) {
  443 + fail_result.push({
  444 + type: 8,
  445 + reason: "未保持正脸拍摄"
  446 + })
  447 + }
  448 + }
  449 + if (fail_result.length > 0) {
  450 + fail_result = JSON.stringify(fail_result);
  451 + th.go_error1(fail_result);
  452 + return false;
  453 + }
  454 + th.analyse_by_mt(img_info,analyse_info);
  455 + },
  456 + fail(err) {
  457 + console.log(err);
  458 + th.go_error1('识别有误,请重试');
  459 + return false;
  460 + }
  461 + })
  462 +
  463 + },
  464 + //美图测肤接口
  465 + analyse_by_mt(img_info,analyse_info) {
  466 + let th = this;
  467 + var plugin = requirePlugin('mtSkinSdk')
  468 + plugin.detectImage({
  469 + path: img_info['path'],
  470 + size: img_info['size'],
  471 + success(res) {
  472 + console.log('=========用户传图片链接获取检测结果 成功==========')
  473 + console.log('检测结果', res);
  474 + let analyse_data = res.data.face_attributes;
  475 + analyse_data['face_rectangle'] = res.data.face_rectangle;
  476 + let req_data = {
  477 + store_id: setting.stoid,
  478 + user_id: getApp().globalData.user_id,
  479 + img: getApp().globalData.face_img,
  480 + sourceimg: getApp().globalData.face_SourceImg,
  481 + addtime: ut.gettimestamp(),
  482 + resultjson: JSON.stringify(analyse_data),
  483 + detectjson: JSON.stringify(analyse_info),
  484 + skin_type: 1,
  485 + }
  486 + //要保存一下分析的结果
  487 + th.json_post("/api/weshop/face/storeSkinface/save", req_data, function (res) {
  488 + if (res.data.code == 0) {
  489 + let url = "/packageD/pages/AI-test-skin/success_result/success_result?id=" + res.data.data.id; //跳到分析页
  490 + wx.redirectTo({
  491 + url: url
  492 + })
  493 + } else {
  494 + getApp().showWarning("保存失败");
  495 + }
  496 + })
  497 + },
  498 + fail(err) {
  499 + console.error('=========用户传图片链接获取检测结果 失败==========')
  500 + console.log('error', err)
  501 + getApp().showWarning(err);
  502 + }
  503 + })
  504 + },
  505 + //百度测肤接口
  506 + analyse_by_bd: function (data) {
  507 + var th = this;
326 508 //开始调用接口,进行分析
327   - this.json_post("/api/weshop/baidubce/face/skinAnalyze",data,function (res) {
328   - if(res.data.code==0){
329   - getApp().globalData.face_result=res.data.data;
330   - var req_data={
331   - store_id:setting.stoid,
332   - user_id:getApp().globalData.user_id,
333   - img:getApp().globalData.face_img,
334   - sourceimg:getApp().globalData.face_SourceImg,
335   - addtime:ut.gettimestamp(),
336   - resultjson:JSON.stringify(res.data.data),
337   - detectjson:JSON.stringify(th.data.check_data)
  509 + this.json_post("/api/weshop/baidubce/face/skinAnalyze", data, function (res) {
  510 + if (res.data.code == 0) {
  511 + getApp().globalData.face_result = res.data.data;
  512 + var req_data = {
  513 + store_id: setting.stoid,
  514 + user_id: getApp().globalData.user_id,
  515 + img: getApp().globalData.face_img,
  516 + sourceimg: getApp().globalData.face_SourceImg,
  517 + addtime: ut.gettimestamp(),
  518 + resultjson: JSON.stringify(res.data.data),
  519 + detectjson: JSON.stringify(th.data.check_data),
  520 + skin_type: 0,
338 521 }
339 522 //要保存一下分析的结果
340   - th.json_post("/api/weshop/face/storeSkinface/save",req_data,function (res) {
341   - if(res.data.code==0){
342   - let url = "/packageD/pages/AI-test-skin/success_result/success_result?id="+res.data.data.id; //跳到分析页
  523 + th.json_post("/api/weshop/face/storeSkinface/save", req_data, function (res) {
  524 + if (res.data.code == 0) {
  525 + let url = "/packageD/pages/AI-test-skin/success_result/success_result?id=" + res.data.data.id; //跳到分析页
343 526 wx.redirectTo({
344 527 url: url
345 528 })
346   - }else{
  529 + } else {
347 530 getApp().showWarning("保存失败");
348 531 }
349 532 })
350   - }else{
351   - var msg=th.data.err_map[res.data.code+""];
352   - let url = "/packageD/pages/AI-test-skin/fail_result/fail_result?msg="+msg; //跳到分析页
  533 + } else {
  534 + var msg = th.data.err_map[res.data.code + ""];
  535 + let url = "/packageD/pages/AI-test-skin/fail_result/fail_result?msg=" + msg; //跳到分析页
353 536 wx.redirectTo({
354   - url: url
  537 + url: url
355 538 })
356 539 }
357 540 })
358 541 },
  542 + //跳转到错误页面 美图
  543 + go_error: function (fail_result) {
  544 + let url = `/packageD/pages/AI-test-skin/fail_result/fail_result?fail_result=${fail_result}`; //跳到分析页
  545 + wx.redirectTo({
  546 + url: url
  547 + });
  548 + },
  549 + //跳转到错误页面
  550 + go_error1: function (msg) {
  551 + let url = "/packageD/pages/AI-test-skin/fail_result/fail_result?msg=" + msg; //跳到分析页
  552 + wx.redirectTo({
  553 + url: url
  554 + });
  555 + },
359 556  
360 557 /**
361 558 * @param {Object} url //url地址
... ... @@ -363,10 +560,10 @@ Page({
363 560 * @param {Object} succ //成功的回调
364 561 * @param {Object} fail //失败的回调
365 562 */
366   - json_post:function(url,data,succ,fail,mathod){
367   - var Mathod="POST";
  563 + json_post: function (url, data, succ, fail, mathod) {
  564 + var Mathod = "POST";
368 565 if (mathod) Mathod = mathod;
369   - if(url.indexOf("http")==-1) url=getApp().globalData.setting.url +url;
  566 + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url;
370 567 var str = JSON.stringify(data);
371 568 wx.request({
372 569 url: url,
... ... @@ -375,10 +572,8 @@ Page({
375 572 header: {
376 573 'content-type': 'application/json'
377 574 },// 设置请求的 header
378   - success: function (res) {succ(res); },
379   - fail:function(res){fail(res);}
  575 + success: function (res) { succ(res); },
  576 + fail: function (res) { fail(res); }
380 577 })
381 578 },
382   -
383   -
384 579 })
385 580 \ No newline at end of file
... ...
packageD/pages/AI-test-skin/fail_result/fail_result.js
1 1 /*
2 2 * @Author: your name
3 3 * @Date: 2022-02-15 10:01:57
4   - * @LastEditTime: 2022-02-16 15:40:54
  4 + * @LastEditTime: 2022-02-28 15:51:37
5 5 * @LastEditors: Please set LastEditors
6 6 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AEet urkl
7 7 * @FilePath: \MShopWeApp\packageB\pages\AI-test-skin\shoot_notice\shoot_notice.js
... ... @@ -20,15 +20,26 @@ Page({
20 20 data: {
21 21 iurl: setting.imghost,
22 22 msg:null,
  23 + fail_result:new Array(), //失败原因
23 24 },
24 25  
25 26 /**
26 27 * 生命周期函数--监听页面加载
27 28 */
28 29 onLoad: function (options) {
29   - var msg=options.msg;
30   - msg=decodeURIComponent(msg);
31   - this.setData({msg:msg});
  30 + if(options?.fail_result){
  31 + var fail_result = JSON.parse(options.fail_result);
  32 + this.setData({
  33 + fail_result,
  34 + })
  35 + }
  36 + if(options?.msg){
  37 + this.setData({
  38 + msg:options.msg
  39 + })
  40 + }
  41 + // msg=decodeURIComponent(msg);
  42 + // this.setData({msg:msg});
32 43 },
33 44  
34 45 /**
... ...
packageD/pages/AI-test-skin/fail_result/fail_result.wxml
... ... @@ -6,17 +6,29 @@
6 6 <text class="iconfont .icon-infofill" style="color:red;font-size: 40rpx;position:absolute;left: -8rpx;top: 0;"></text>
7 7 </view>
8 8 </view>
9   - <view style="font-size:32rpx;color: #333">上传图片符合要求</view>
  9 + <view style="font-size:32rpx;color: #333">上传图片符合要求</view>
10 10 <view style="font-size: 26rpx;color: #555">请重新更换图片获取相关检测</view>
11 11 <view style="border-bottom: 1rpx solid #eee; margin:0 40rpx;margin-top:40rpx;"></view>
12 12 </view>
13 13  
14 14 <view style="padding:60rpx; padding-bottom: 70rpx;">
15   - <view style="font-size: 32rpx;">失败原因:</view>
16   - <view style="font-size: 26rpx;display: flex;align-items: center; margin-top: 20prx">
17   - <text class="iconfont icon-geren" style="font-size: 56rpx;margin-right: 20rpx"></text>
18   - <view>{{msg}}</view>
19   - </view>
  15 + <view style="font-size: 32rpx;margin-bottom: 6rpx;">失败原因:</view>
  16 + <block wx:if="{{!msg}}">
  17 + <view style="font-size: 26rpx; margin-top: 20prx" wx:for="{{fail_result}}" wx:key="type">
  18 + <view style="display: flex;align-items: center;">
  19 + <text class="iconfont icon-info" style="margin-right: 20rpx"></text>
  20 + <view>{{item.reason}}</view>
  21 + </view>
  22 + </view>
  23 + </block>
  24 + <block wx:else>
  25 + <view style="font-size: 26rpx; margin-top: 20prx">
  26 + <view style="display: flex;align-items: center;">
  27 + <text class="iconfont icon-info" style="margin-right: 20rpx"></text>
  28 + <view>{{msg}}</view>
  29 + </view>
  30 + </view>
  31 + </block>
20 32 </view>
21 33  
22 34 </view>
... ...
packageD/pages/AI-test-skin/select_photo/select_photo.js
1   -/*
2   - * @Author: your name
3   - * @Date: 2022-02-16 14:34:42
4   - * @LastEditTime: 2022-02-16 15:42:25
5   - * @LastEditors: Please set LastEditors
6   - * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
7   - * @FilePath: \MShopWeApp\packageB\pages\AI-test-skin\select_photo\select_photo.js
8   - */
9 1 // packageB/pages/AI-test-skin/select_photo/select_photo.js
10 2 const app = getApp();
11 3 const request = app.request;
... ... @@ -20,20 +12,21 @@ Page({
20 12 data: {
21 13 iurl: setting.imghost,
22 14 gl_skin_img: null,
  15 + skin_type: 0,
23 16 },
24 17  
25 18 /**
26 19 * 生命周期函数--监听页面加载
27 20 */
28 21 onLoad: function (options) {
29   - var img=getApp().globalData.skin_img;
30   - this.setData({gl_skin_img:img})
  22 + var img = getApp().globalData.skin_img_info;
  23 + this.setData({ gl_skin_img: img })
31 24 },
32 25  
33 26 /**
34 27 * 生命周期函数--监听页面显示
35 28 */
36   - onShow: function () {},
  29 + onShow: function () { },
37 30  
38 31 /**
39 32 * 生命周期函数--监听页面隐藏
... ... @@ -56,19 +49,22 @@ Page({
56 49 },
57 50  
58 51 //-- 完成选择 --
59   - ok_select:function () {
60   - var th=this;
61   - app.request.uploadFile("/api/weshop/baidubce/face/uploadImg?uploadPath=faceimg&storeId="+setting.stoid, {
62   - filePath: th.data.gl_skin_img,
  52 + ok_select: function () {
  53 + const th = this;
  54 + let filePath = th.data.gl_skin_img['path'];
  55 + console.log('filePath', filePath);
  56 + // if (th.data.skin_type) {
  57 + // filePath = th.data.gl_skin_img['path'];
  58 + // }
  59 + app.request.uploadFile("/api/weshop/baidubce/face/uploadImg?uploadPath=faceimg&storeId=" + setting.stoid, {
  60 + filePath: th.data.gl_skin_img['path'],
63 61 name: "file",
64 62 success: function (e) {
65   - if(e.data.code==0) {
66   - getApp().globalData.face_img=e.data.data.img;
67   - getApp().globalData.face_SourceImg=e.data.data.SourceImg;
68   -
  63 + if (e.data.code == 0) {
  64 + getApp().globalData.face_img = e.data.data.img;
  65 + getApp().globalData.face_SourceImg = e.data.data.SourceImg;
69 66 let url = "/packageD/pages/AI-test-skin/analyse/analyse"; //跳到分析页
70 67 app.goto(url);
71   -
72 68 } else {
73 69 wx.showToast({
74 70 title: e.data.msg,
... ... @@ -79,25 +75,133 @@ Page({
79 75 }
80 76 });
81 77 },
82   -
83 78 //-- 重新从相册中选择图片 --
84   - show_pai_pop:function () {
85   - var th=this;
  79 + show_pai_pop: function () {
  80 + var th = this;
86 81 //选择和拍照一张图片
87 82 wx.chooseImage({
88 83 count: 1,
89 84 sizeType: ['original', 'compressed'],
90 85 sourceType: ['album', 'camera'],
91   - success (res) {
  86 + success(res) {
92 87 let imgArr = res.tempFilePaths;
93   - getApp().globalData.skin_img=imgArr[0];
94   - th.setData({gl_skin_img:imgArr[0]})
  88 + if (th.data.skin_type) {
  89 + imgArr = res.tempFiles;
  90 + }
  91 + getApp().globalData.skin_img_info = imgArr[0];
  92 + th.setData({ gl_skin_img: imgArr[0] })
95 93 }
96 94 })
97   -
98 95 },
99   -
100   -
101   -
102   -
  96 + //选择图片
  97 + takePhoto() {
  98 + var that = this;
  99 + wx.chooseImage({
  100 + count: 1,
  101 + sizeType: ['compressed'],
  102 + sourceType: ['album', 'camera'],
  103 + success(res) {
  104 + var tempFilePaths = res.tempFilePaths
  105 + console.log(tempFilePaths);
  106 + console.log(res.tempFiles[0].size / 1024 + 'kb');
  107 + var size1 = res.tempFiles[0].size;
  108 + var size = res.tempFiles[0].size / 1024; //kb单位
  109 + // tempFilePath可以作为img标签的src属性显示图片
  110 + var img = tempFilePaths[0];
  111 + that.setData({
  112 + imagesrc: img,
  113 + })
  114 + that.imgToMin(img, size, size1); //获取图片后压缩
  115 +
  116 + },
  117 + fail(err) {
  118 + console.log(err);
  119 + }
  120 + })
  121 + },
  122 + //缩放图片
  123 + imgToMin(img, size, size1) {
  124 + var that = this;
  125 + //size小于100kb 时 直接转码识别
  126 + if (size < 1024) {
  127 + getApp().globalData.skin_img_info = {
  128 + path:img,
  129 + size,
  130 + }
  131 + let url = "/packageD/pages/AI-test-skin/select_photo/select_photo";
  132 + app.goto(url);
  133 + // that.base64(img,"jpg");
  134 + return;
  135 + }
  136 +
  137 + //先获取图片 然后根据长宽 缩小 之后获取图片
  138 + wx.getImageInfo({
  139 + src: img,
  140 + success(res) {
  141 + var ratio = Math.trunc(size / 1024);
  142 + size1 = size1 / ratio;
  143 + var canvasWidth = res.width //图片原始长宽
  144 + var canvasHeight = res.height
  145 + //while (canvasWidth > 375 || canvasHeight > 520){// 保证宽高在400以内
  146 + canvasWidth = Math.trunc(canvasWidth / ratio)
  147 + canvasHeight = Math.trunc(canvasHeight / ratio)
  148 + //ratio++;
  149 + //}
  150 + that.setData({ canvasWidth: canvasWidth, canvasHeight: canvasHeight })
  151 + console.log(canvasWidth)
  152 + console.log(canvasHeight)
  153 + //绘制图片
  154 + var ctx = wx.createCanvasContext('attendCanvasId')
  155 + ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight)
  156 + ctx.draw(false, setTimeout(function () {
  157 + wx.canvasToTempFilePath({
  158 + canvasId: 'attendCanvasId',
  159 + width: canvasWidth,
  160 + height: canvasHeight,
  161 + destWidth: canvasWidth,
  162 + destHeight: canvasHeight,
  163 + fileType: 'jpg',
  164 + success: function (res) {
  165 + console.log(res.tempFilePath)//最终图片路径
  166 + that.setData({
  167 + canvasImgUrl: res.tempFilePath
  168 + });
  169 + getApp().globalData.skin_img_info = {
  170 + path: res.tempFilePath,
  171 + size: size1
  172 + };
  173 + let url = "/packageD/pages/AI-test-skin/select_photo/select_photo";
  174 + app.goto(url);
  175 + },
  176 + fail: function (res) {
  177 + console.log("缩放图片失败");
  178 + console.log(res.errMsg)
  179 + wx.hideLoading();
  180 + wx.showToast({
  181 + title: '识别图片失败',
  182 + image: '../../utils/img/wrong.png',
  183 + duration: 2000
  184 + })
  185 + that.setData({
  186 + title: "识别失败",
  187 + })
  188 + }
  189 + }, this) //要填写this对象,表示canvas这个对象
  190 + }, 1000)) //留一定的时间绘制canvas 否则会报错fail canvas is empty
  191 + },
  192 + fail: function (res) {
  193 + console.log("获取图片失败");
  194 + console.log(res.errMsg)
  195 + wx.hideLoading();
  196 + wx.showToast({
  197 + title: '识别图片失败',
  198 + image: '../../utils/img/wrong.png',
  199 + duration: 2000
  200 + })
  201 + that.setData({
  202 + title: "识别失败",
  203 + })
  204 + },
  205 + })
  206 + },
103 207 })
104 208 \ No newline at end of file
... ...
packageD/pages/AI-test-skin/select_photo/select_photo.wxml
1 1 <view class="content" style="height: 70%;">
2 2 <view style="height: 100%;;display:flex;align-items:center;overflow: hidden;">
3   - <image style="height: 100%;width: 100%;border-radius: 3%;" mode="widthFix" src="{{gl_skin_img}}"></image>
  3 + <image style="width: 100%;border-radius: 3%;" mode="widthFix" src="{{gl_skin_img['path']}}"></image>
  4 + <!-- <image wx:else style="width: 100%;border-radius: 3%;" mode="widthFix" src="{{gl_skin_img['path']}}"></image> -->
4 5 </view>
5 6 <view class="foot_btn">
6   - <view class="reset_select" bindtap="show_pai_pop">
  7 + <view class="reset_select" bindtap="takePhoto">
7 8 <text class="iconfont icon-zuojiantou" style="font-size: 40rpx"></text>
8 9 <text style="font-size: 28rpx">重拍</text>
9 10 </view>
... ...
packageD/pages/AI-test-skin/shoot_notice/shoot_notice.js
1 1 /*
2 2 * @Author: abson
3 3 * @Date: 2022-02-15 10:01:57
4   - * @LastEditTime: 2022-02-28 15:37:20
  4 + * @LastEditTime: 2022-03-02 11:44:11
5 5 * @LastEditors: Please set LastEditors
6 6 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AEet urkl
7 7 * @FilePath: \MShopWeApp\packageB\pages\AI-test-skin\shoot_notice\shoot_notice.js
... ... @@ -19,7 +19,10 @@ Page({
19 19 */
20 20 data: {
21 21 iurl: setting.imghost,
22   - notice_show:"",
  22 + notice_show: "",
  23 + skin_type: 0,
  24 + cWidth: 0,
  25 + cHeight: 0,
23 26 },
24 27  
25 28 /**
... ... @@ -33,11 +36,12 @@ Page({
33 36 * 生命周期函数--监听页面显示
34 37 */
35 38 onShow: function () {
36   - setTimeout(()=>{
37   - this.setData({
38   - notice_show:'none',
  39 + let th = this;
  40 + setTimeout(() => {
  41 + th.setData({
  42 + notice_show: 'none',
39 43 })
40   - },3000).bind(this)
  44 + }, 3000)
41 45 },
42 46  
43 47 /**
... ... @@ -70,13 +74,19 @@ Page({
70 74  
71 75 //从相册中选择图片
72 76 show_pai_pop: function () {
  77 + let th = this;
73 78 //选择和拍照一张图片
74 79 wx.chooseImage({
75 80 count: 1,
76 81 sizeType: ['original', 'compressed'],
77 82 sourceType: ['album', 'camera'],
78 83 success(res) {
79   - let imgArr = res.tempFiles;
  84 + let imgArr = res.tempFilePaths;
  85 + //
  86 + if (th.data.skin_type) {
  87 + imgArr = res.tempFiles;
  88 + }
  89 + console.log(imgArr);
80 90 getApp().globalData.skin_img_info = imgArr[0];
81 91 let url = "/packageD/pages/AI-test-skin/select_photo/select_photo";
82 92 app.goto(url);
... ... @@ -85,7 +95,134 @@ Page({
85 95  
86 96 },
87 97  
  98 + //选择图片
  99 + takePhoto() {
  100 + var that = this;
88 101  
89   -
90   -
  102 + wx.chooseImage({
  103 + count: 1,
  104 + sizeType: ['compressed'],
  105 + sourceType: ['album', 'camera'],
  106 + success(res) {
  107 + var tempFilePaths = res.tempFilePaths
  108 + console.log(tempFilePaths);
  109 + console.log(res.tempFiles[0].size / 1024 + 'kb');
  110 + var size1 =res.tempFiles[0].size;
  111 + var size = res.tempFiles[0].size / 1024; //kb单位
  112 + // tempFilePath可以作为img标签的src属性显示图片
  113 + var img = tempFilePaths[0];
  114 + that.setData({
  115 + imagesrc: img,
  116 + })
  117 + that.imgToMin(img, size,size1); //获取图片后压缩
  118 +
  119 + },
  120 + fail(err) {
  121 + console.log(err);
  122 + }
  123 + })
  124 + },
  125 + //图片转码64
  126 + base64(url, type) {
  127 + var that = this;
  128 + return new Promise((resolve, reject) => {
  129 + wx.getFileSystemManager().readFile({
  130 + filePath: url, //选择图片返回的相对路径
  131 + encoding: 'base64', //编码格式
  132 + success: res => {
  133 + resolve('data:image/' + type.toLocaleLowerCase() + ';base64,' + res.data)
  134 + // console.log(res.data);
  135 + // that.doDiscernment(res.data);//提交后台
  136 + },
  137 + fail: res => reject(res.errMsg)
  138 + })
  139 + })
  140 + },
  141 + //缩放图片
  142 + imgToMin(img, size,size1) {
  143 + var that = this;
  144 + //size小于100kb 时 直接转码识别
  145 + if (size < 1024) {
  146 + getApp().globalData.skin_img_info = {
  147 + path:img,
  148 + size,
  149 + }
  150 + let url = "/packageD/pages/AI-test-skin/select_photo/select_photo";
  151 + app.goto(url);
  152 + // that.base64(img,"jpg");
  153 + return;
  154 + }
  155 +
  156 + //先获取图片 然后根据长宽 缩小 之后获取图片
  157 + wx.getImageInfo({
  158 + src: img,
  159 + success(res) {
  160 + console.log(res.width)
  161 + console.log(res.height)
  162 + var ratio = size / 1024;
  163 + size1 = size1 / ratio;
  164 + var canvasWidth = res.width //图片原始长宽
  165 + var canvasHeight = res.height
  166 + //while (canvasWidth > 375 || canvasHeight > 520){// 保证宽高在400以内
  167 + canvasWidth = Math.trunc(canvasWidth / ratio)
  168 + canvasHeight = Math.trunc(canvasHeight / ratio)
  169 + //ratio++;
  170 + //}
  171 + that.setData({ canvasWidth: canvasWidth, canvasHeight: canvasHeight })
  172 + console.log(canvasWidth)
  173 + console.log(canvasHeight)
  174 + //绘制图片
  175 + var ctx = wx.createCanvasContext('attendCanvasId')
  176 + ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight)
  177 + ctx.draw(false, setTimeout(function () {
  178 + wx.canvasToTempFilePath({
  179 + canvasId: 'attendCanvasId',
  180 + width: canvasWidth,
  181 + height: canvasHeight,
  182 + destWidth: canvasWidth,
  183 + destHeight: canvasHeight,
  184 + fileType: 'jpg',
  185 + success: function (res) {
  186 + console.log(res.tempFilePath)//最终图片路径
  187 + that.setData({
  188 + canvasImgUrl: res.tempFilePath
  189 + });
  190 + getApp().globalData.skin_img_info = {
  191 + path:res.tempFilePath,
  192 + size:size1
  193 + };
  194 + let url = "/packageD/pages/AI-test-skin/select_photo/select_photo";
  195 + app.goto(url);
  196 + },
  197 + fail: function (res) {
  198 + console.log("缩放图片失败");
  199 + console.log(res.errMsg)
  200 + wx.hideLoading();
  201 + wx.showToast({
  202 + title: '识别图片失败',
  203 + image: '../../utils/img/wrong.png',
  204 + duration: 2000
  205 + })
  206 + that.setData({
  207 + title: "识别失败",
  208 + })
  209 + }
  210 + }, this) //要填写this对象,表示canvas这个对象
  211 + }, 1000)) //留一定的时间绘制canvas 否则会报错fail canvas is empty
  212 + },
  213 + fail: function (res) {
  214 + console.log("获取图片失败");
  215 + console.log(res.errMsg)
  216 + wx.hideLoading();
  217 + wx.showToast({
  218 + title: '识别图片失败',
  219 + image: '../../utils/img/wrong.png',
  220 + duration: 2000
  221 + })
  222 + that.setData({
  223 + title: "识别失败",
  224 + })
  225 + },
  226 + })
  227 + },
91 228 })
92 229 \ No newline at end of file
... ...
packageD/pages/AI-test-skin/shoot_notice/shoot_notice.wxml
... ... @@ -50,9 +50,12 @@
50 50 </view>
51 51 </view>
52 52 </view>
  53 +
  54 +<canvas canvas-id="attendCanvasId" style="width:{{canvasWidth}}px;height:{{canvasHeight}}px;position: absolute;z-index:1003;left:-500rpx;"></canvas>
  55 +
53 56 <view style="height: 300rpx;background-color: #e7f5fb;">
54 57 <view class="btn_fixed">
55   - <view class="btn" bindtap="show_pai_pop">准备闭眼拍摄</view>
  58 + <view class="btn" bindtap="takePhoto">准备闭眼拍摄</view>
56 59 <view class="notice" style="display:flex;justify-content:center;align-items: center;">
57 60 <text class="iconfont icon-info" style="margin-right: 10rpx;font-size: 26rpx"></text>
58 61 <text>如无闭眼,将导致图片分析失败</text>
... ...
packageD/pages/AI-test-skin/success_result/sensitive/sensitive.js
... ... @@ -2,7 +2,6 @@ module.exports = {
2 2 //把组合购的商品价格计算出来,同时每个会员都有购买组合商品的上限!ladder_b_num是已经购买了多少件
3 3 get_goods: function (th, stoid,sort) {
4 4 th.setData({sensitive_sort:sort});
5   -
6 5 var r_code = '12';
7 6 //获取毛孔的类型
8 7 var arr = th.data.face_data.skinquality.skin_sensitive_check;
... ...
packageD/pages/AI-test-skin/success_result/success_result.js
1 1 /*
2 2 * @Author: abson
3 3 * @Date: 2022-02-16 15:36:47
4   - * @LastEditTime: 2022-02-28 10:44:27
  4 + * @LastEditTime: 2022-02-28 16:01:07
5 5 * @LastEditors: Please set LastEditors
6 6 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
7 7 * @FilePath: \MShopWeApp\packageB\pages\AI-test-skin\success_result\success_result.js
... ... @@ -19,6 +19,7 @@ const dark = require(&#39;dark/dark&#39;);
19 19 const pore = require('pore/pore');
20 20 const speckle = require('speckle/speckle');
21 21 const wrinkle = require('wrinkle/wrinkle');
  22 +const sensitive = require('sensitive/sensitive')
22 23 Page({
23 24 /**
24 25 * 页面的初始数据
... ... @@ -27,13 +28,13 @@ Page({
27 28 // tab: [{ id: 'zong_he', name: '综合肤质' }, { id: 'mao_kong', name: '毛孔' }, { id: 'hei_tou', name: '黑头' }, { id: 'se_ban', name: '色斑' }, { id: 'zhou_wen', name: '皱纹' }, { id: 'hei_yan_quan', name: '黑眼圈' }, { id: 'cuo_chuang', name: '痤疮' }, { id: 'min_gan_du', name: '敏感度' }],
28 29 zhouwen_arr: [{ id: 1, name: '全部皱纹' }, { id: 2, name: '抬头纹' }, { id: 3, name: '川字纹' }, { id: 4, name: '眼周细纹' }, { id: 5, name: '鱼尾纹' }, { id: 6, name: '法令纹' }, { id: 7, name: '口周纹' }],
29 30 cuochuang_arr: [{ id: 1, name: '全部痤疮' }, { id: 2, name: '粉刺 ' }, { id: 3, name: '痘印 ' }, { id: 4, name: '脓包' }, { id: 5, name: '结节' }],
30   - zhouwen_arr1: [{ id: 1, name: '皱纹/细纹',des:'是指皮肤受到外界环境影响,形成游离自由基,自由基破坏正常细胞膜组织内的胶原蛋白、活性物质,氧化细胞,或缺水而形成的小细纹,继而严重形成皱纹',sign: 'zhou1',sign1: 'zhou2' }, { id: 2, name: '抬头皱纹/抬头细纹',des:'位于额头的皱纹、细纹。形成原因因人而异,后天因素是比较少的。-般多为横纹, 竖纹较少见。' ,sign: 'zhou3',sign1:'zhou4'}, { id: 3, name: '眼部皱纹/眼部细纹',des:'眼部皱纹、细纹一般位于下眼睑部位,多见于下脸内1/3处。',sign:'zhou5',sign1:'zhou6' }, { id: 4, name: '鱼尾纹',des:'眼部皱纹的一种,是在人两侧外眼角和登角之间出现的皱纹,其纹路与鱼尾巴上的纹路很相似,故被形象地称为鱼尾纹。',sign:'zhou7',sign1:'zhou8' }, { id: 5, name: '眉间纹',des:'又叫川字纹,皱眉纹,是面部的一种正常的表情纹,随着年龄的增长,面部的皱纹会逐渐加深,双眉之间逐渐形成了较深的皱折,会使人看起来总是愁眉不展。',sign:'zhou9',sign1:'zhou10'}, { id: 6, name: '泪沟',des:'泪沟是指由内眼角开始出现在下眼睑靠鼻侧的两条凹沟,是由于眼眶隔膜下缘的软组织萎缩、下垂而生成的。',sign:'zhou11',sign1:'zhou12' }, { id: 7, name: '法令纹',des:'法令纹是位于鼻翼边延伸而下的两道纹路,是典型的皮肤组织老化、造成肌肤表面凹陷的现象。',sign:'zhou15',sign1:'zhou16' }, { id: 8, name: '口角纹',des:'口角纹又称木偶纹、括号纹,位于嘴角延伸而下的两道纹路,是表情肌、重力和遗传基因等几方面因素综合形成的。',sign:'zhou13',sign1:'zhou14' }],
31   - cuochuang_arr1: [{ id: 1, name: '痘印,痘坑',des:'痤疮消退后留下的痕迹,- 般包括黑色痘印,红色痘印,凹洞性痘坑,增生性凸疤。', sign: 'cuo1',sign1: 'cuo2'}, { id: 2, name: '粉刺',des:'粉刺也称为白头,是毛囊漏斗部被角质层细胞堆积、堵塞,角化物质和皮脂充塞其中,形成白色丘疹,表面有表皮覆盖,与外界不相通,成为封闭式粉刺。(痤疮I级)', sign: 'cuo3',sign1: 'cuo4' }, { id: 3, name: '丘疹',des:'丘疹性痤疮是由皮损导致炎性弓|起的小米至豌豆大的坚硬的小丘疹,呈淡红色至深红色。丘疹中央可有一个黑头粉刺或顶端未变黑的皮脂栓。(痤疮II级)', sign: 'cuo5',sign1: 'cuo6' }, { id: 4, name: '结节囊肿',des:'表现为蚕豆至指甲大的炎性结节或囊肿,为重度痤疮,严重者可继发化脓感染、破溃流出血脓,后形成窦道及瘢痕。触摸有波动感。若面部相邻长着多个囊肿,可能通过皮下的“窦道"“暗通,可能需要手术解决。(痤疮IV级)',sign:'cuo7',sign1:'cuo8' }],
  31 + zhouwen_arr1: [{ id: 1, name: '皱纹/细纹', des: '是指皮肤受到外界环境影响,形成游离自由基,自由基破坏正常细胞膜组织内的胶原蛋白、活性物质,氧化细胞,或缺水而形成的小细纹,继而严重形成皱纹', sign: 'zhou1', sign1: 'zhou2' }, { id: 2, name: '抬头皱纹/抬头细纹', des: '位于额头的皱纹、细纹。形成原因因人而异,后天因素是比较少的。-般多为横纹, 竖纹较少见。', sign: 'zhou3', sign1: 'zhou4' }, { id: 3, name: '眼部皱纹/眼部细纹', des: '眼部皱纹、细纹一般位于下眼睑部位,多见于下脸内1/3处。', sign: 'zhou5', sign1: 'zhou6' }, { id: 4, name: '鱼尾纹', des: '眼部皱纹的一种,是在人两侧外眼角和登角之间出现的皱纹,其纹路与鱼尾巴上的纹路很相似,故被形象地称为鱼尾纹。', sign: 'zhou7', sign1: 'zhou8' }, { id: 5, name: '眉间纹', des: '又叫川字纹,皱眉纹,是面部的一种正常的表情纹,随着年龄的增长,面部的皱纹会逐渐加深,双眉之间逐渐形成了较深的皱折,会使人看起来总是愁眉不展。', sign: 'zhou9', sign1: 'zhou10' }, { id: 6, name: '泪沟', des: '泪沟是指由内眼角开始出现在下眼睑靠鼻侧的两条凹沟,是由于眼眶隔膜下缘的软组织萎缩、下垂而生成的。', sign: 'zhou11', sign1: 'zhou12' }, { id: 7, name: '法令纹', des: '法令纹是位于鼻翼边延伸而下的两道纹路,是典型的皮肤组织老化、造成肌肤表面凹陷的现象。', sign: 'zhou15', sign1: 'zhou16' }, { id: 8, name: '口角纹', des: '口角纹又称木偶纹、括号纹,位于嘴角延伸而下的两道纹路,是表情肌、重力和遗传基因等几方面因素综合形成的。', sign: 'zhou13', sign1: 'zhou14' }],
  32 + cuochuang_arr1: [{ id: 1, name: '痘印,痘坑', des: '痤疮消退后留下的痕迹,- 般包括黑色痘印,红色痘印,凹洞性痘坑,增生性凸疤。', sign: 'cuo1', sign1: 'cuo2' }, { id: 2, name: '粉刺', des: '粉刺也称为白头,是毛囊漏斗部被角质层细胞堆积、堵塞,角化物质和皮脂充塞其中,形成白色丘疹,表面有表皮覆盖,与外界不相通,成为封闭式粉刺。(痤疮I级)', sign: 'cuo3', sign1: 'cuo4' }, { id: 3, name: '丘疹', des: '丘疹性痤疮是由皮损导致炎性弓|起的小米至豌豆大的坚硬的小丘疹,呈淡红色至深红色。丘疹中央可有一个黑头粉刺或顶端未变黑的皮脂栓。(痤疮II级)', sign: 'cuo5', sign1: 'cuo6' }, { id: 4, name: '结节囊肿', des: '表现为蚕豆至指甲大的炎性结节或囊肿,为重度痤疮,严重者可继发化脓感染、破溃流出血脓,后形成窦道及瘢痕。触摸有波动感。若面部相邻长着多个囊肿,可能通过皮下的“窦道"“暗通,可能需要手术解决。(痤疮IV级)', sign: 'cuo7', sign1: 'cuo8' }],
32 33 heitanquan_arr: [{ id: 1, name: '综合情况' }, { id: 2, name: '左眼' }, { id: 3, name: '右眼' }],
33   - heitanquan_arr1: [{ id: 1, name: '色素性黑眼圈', des: '呈茶褐色,是因眼裂向外眼角的延伸段有色素沉着或因先天或外来刺激导致眼周肤色黯沉。', sign: 'hei1',sign1: 'hei2' }, { id: 2, name: '血管性黑眼圈', des: '呈青紫色,由于眼周血液循环不良,下眼脸处皮肤与皮下脂肪变薄,皮下血管透出颜色形成的。', sign: 'hei3',sign1: 'hei4' }, { id: 3, name: '阴影型黑眼圈', des: '表现为眼袋膨出、泪沟凹陷。由于年龄的增长,眼周皮肤肌肉都会变得松弛,脂肪量变化而引起。', sign: 'hei5',sign1: 'hei6' }],
  34 + heitanquan_arr1: [{ id: 1, name: '色素性黑眼圈', des: '呈茶褐色,是因眼裂向外眼角的延伸段有色素沉着或因先天或外来刺激导致眼周肤色黯沉。', sign: 'hei1', sign1: 'hei2' }, { id: 2, name: '血管性黑眼圈', des: '呈青紫色,由于眼周血液循环不良,下眼脸处皮肤与皮下脂肪变薄,皮下血管透出颜色形成的。', sign: 'hei3', sign1: 'hei4' }, { id: 3, name: '阴影型黑眼圈', des: '表现为眼袋膨出、泪沟凹陷。由于年龄的增长,眼周皮肤肌肉都会变得松弛,脂肪量变化而引起。', sign: 'hei5', sign1: 'hei6' }],
34 35 currentIndex: 0,
35 36 scroll_index: 0,
36   - yiwen_index:0,
  37 + yiwen_index: 0,
37 38 sex: 'female', //female女 male男
38 39 tab_id: 'zong_he',
39 40 iurl: setting.imghost,
... ... @@ -54,17 +55,17 @@ Page({
54 55 wrinkle_num4: 0, //鱼尾纹
55 56 wrinkle_num5: 0, //法令纹
56 57 wrinkle_num6: 0, //口周纹
57   - yiwen_type:0, //1皱纹 2黑眼圈 3痤疮
  58 + yiwen_type: 0, //1皱纹 2黑眼圈 3痤疮
58 59 acne_num1: 0, //粉刺
59 60 acne_num2: 0, //痘印
60 61 acne_num3: 0, //脓包
61 62 acne_num4: 0, //结节
62 63 },
63 64  
64   - onReady:function () {
  65 + onReady: function () {
65 66 //用异步的获取比较准一点
66 67 wx.getSystemInfo({
67   - success (res) {
  68 + success(res) {
68 69 console.log(111);
69 70 console.log(res.windowWidth);
70 71 console.log(res.windowHeight);
... ... @@ -86,7 +87,7 @@ Page({
86 87  
87 88 //用异步的获取比较准一点
88 89 wx.getSystemInfo({
89   - success (res) {
  90 + success(res) {
90 91 //计算图片要显示的大小
91 92 th.data.cWidth = res.windowWidth;
92 93 th.data.cHeight = res.windowHeight;
... ... @@ -98,7 +99,7 @@ Page({
98 99  
99 100 th.data.face_height = th.data.cHeight * 0.8 * 0.75;
100 101  
101   - var bi1= (th.data.cHeight * 0.8 * 0.8)/(th.data.cWidth*0.8);
  102 + var bi1 = (th.data.cHeight * 0.8 * 0.8) / (th.data.cWidth * 0.8);
102 103 th.get_data(function (json, json1, img) {
103 104 //-- 数据先存着 --
104 105 var face_data = th.data.face_data = json.face_list[0];
... ... @@ -118,8 +119,8 @@ Page({
118 119 var dark_type = face_data.eyesattr.dark_circle_left_type.length > 0 ? face_data.eyesattr.dark_circle_left_type[0] : -1;
119 120 var dark_type1 = face_data.eyesattr.dark_circle_right_type.length > 0 ? face_data.eyesattr.dark_circle_right_type[0] : -1;
120 121  
121   - var dk_type1=dark_type;
122   - var dk_type2=dark_type1;
  122 + var dk_type1 = dark_type;
  123 + var dk_type2 = dark_type1;
123 124 if (dark_type1 > dark_type) {
124 125 dark_type = dark_type1;
125 126 }
... ... @@ -127,103 +128,103 @@ Page({
127 128 var skin_dryoil_check = face_data.skinquality.skin_dryoil_check;
128 129  
129 130 var location = face_data.location;
130   - var bili = th.data.face_height*0.76/location.height;
  131 + var bili = th.data.face_height * 0.76 / location.height;
131 132  
132 133 //获取眼睛的画图比例
133   - var eye_data1=face_data1.landmark150.eye_left_corner_right;
134   - var eye_data2=face_data1.landmark150.eye_left_corner_left;
135   - var eye_data3=face_data1.landmark150.eye_right_corner_right;
136   -
137   - var hei1=Math.abs(eye_data1.x-eye_data2.x);
138   - var bili_eye = th.data.face_height*0.56/hei1;
139   - var eye_top=eye_data1.y-hei1/2
140   - var eye_left1=eye_data1.x-hei1/6;
141   - var eye_left2=eye_data3.x-hei1/6;
142   -
143   - var skin_dryoil_check_type=0;//干性
144   - var skin_dryoil_check_arr=[]
145   - for(let i in skin_dryoil_check){
146   - let item=skin_dryoil_check[i];
147   - if(item!='1' && skin_dryoil_check_arr.indexOf(item)==-1){
  134 + var eye_data1 = face_data1.landmark150.eye_left_corner_right;
  135 + var eye_data2 = face_data1.landmark150.eye_left_corner_left;
  136 + var eye_data3 = face_data1.landmark150.eye_right_corner_right;
  137 +
  138 + var hei1 = Math.abs(eye_data1.x - eye_data2.x);
  139 + var bili_eye = th.data.face_height * 0.56 / hei1;
  140 + var eye_top = eye_data1.y - hei1 / 2
  141 + var eye_left1 = eye_data1.x - hei1 / 6;
  142 + var eye_left2 = eye_data3.x - hei1 / 6;
  143 +
  144 + var skin_dryoil_check_type = 0;//干性
  145 + var skin_dryoil_check_arr = []
  146 + for (let i in skin_dryoil_check) {
  147 + let item = skin_dryoil_check[i];
  148 + if (item != '1' && skin_dryoil_check_arr.indexOf(item) == -1) {
148 149 skin_dryoil_check_arr.push(item);
149 150 }
150 151 }
151 152 //皮肤干油性的判断
152   - if(skin_dryoil_check_arr.length==0) skin_dryoil_check_type=1;
153   - else if(skin_dryoil_check_arr.length==1) skin_dryoil_check_type=parseInt(skin_dryoil_check_arr[0]);
154   - else skin_dryoil_check_type=3;
  153 + if (skin_dryoil_check_arr.length == 0) skin_dryoil_check_type = 1;
  154 + else if (skin_dryoil_check_arr.length == 1) skin_dryoil_check_type = parseInt(skin_dryoil_check_arr[0]);
  155 + else skin_dryoil_check_type = 3;
155 156  
156   - var wrinkle_types=face_data.wrinkle.wrinkle_types;
157   - var w_arr=wrinkle_types.filter(function (e) {
158   - return e==1;
  157 + var wrinkle_types = face_data.wrinkle.wrinkle_types;
  158 + var w_arr = wrinkle_types.filter(function (e) {
  159 + return e == 1;
159 160 })
160   - th.data.wrinkle_num1=w_arr.length;
  161 + th.data.wrinkle_num1 = w_arr.length;
161 162  
162 163 //皱纹的数量的统计
163   - w_arr=wrinkle_types.filter(function (e) {
164   - return e==2;
  164 + w_arr = wrinkle_types.filter(function (e) {
  165 + return e == 2;
165 166 })
166   - th.data.wrinkle_num2=w_arr.length;
167   - w_arr=wrinkle_types.filter(function (e) {
168   - return e==3;
  167 + th.data.wrinkle_num2 = w_arr.length;
  168 + w_arr = wrinkle_types.filter(function (e) {
  169 + return e == 3;
169 170 })
170   - th.data.wrinkle_num3=w_arr.length;
171   - w_arr=wrinkle_types.filter(function (e) {
172   - return e==4;
  171 + th.data.wrinkle_num3 = w_arr.length;
  172 + w_arr = wrinkle_types.filter(function (e) {
  173 + return e == 4;
173 174 })
174   - th.data.wrinkle_num4=w_arr.length;
175   - w_arr=wrinkle_types.filter(function (e) {
176   - return e==5;
  175 + th.data.wrinkle_num4 = w_arr.length;
  176 + w_arr = wrinkle_types.filter(function (e) {
  177 + return e == 5;
177 178 })
178   - th.data.wrinkle_num5=w_arr.length;
179   - w_arr=wrinkle_types.filter(function (e) {
180   - return e==6;
  179 + th.data.wrinkle_num5 = w_arr.length;
  180 + w_arr = wrinkle_types.filter(function (e) {
  181 + return e == 6;
181 182 })
182   - th.data.wrinkle_num6=w_arr.length;
  183 + th.data.wrinkle_num6 = w_arr.length;
183 184  
184 185 //痘痘的不同的统计
185 186 var acne_list = face_data.acnespotmole.acne_list;
186   - var a_arr=acne_list.filter(function (e) {
187   - return e.type==0;
  187 + var a_arr = acne_list.filter(function (e) {
  188 + return e.type == 0;
188 189 })
189   - th.data.acne_num1=a_arr.length;
190   - a_arr=acne_list.filter(function (e) {
191   - return e.type==1;
  190 + th.data.acne_num1 = a_arr.length;
  191 + a_arr = acne_list.filter(function (e) {
  192 + return e.type == 1;
192 193 })
193   - th.data.acne_num2=a_arr.length;
194   - a_arr=acne_list.filter(function (e) {
195   - return e.type==2;
  194 + th.data.acne_num2 = a_arr.length;
  195 + a_arr = acne_list.filter(function (e) {
  196 + return e.type == 2;
196 197 })
197   - th.data.acne_num3=a_arr.length;
198   - a_arr=acne_list.filter(function (e) {
199   - return e.type==3;
  198 + th.data.acne_num3 = a_arr.length;
  199 + a_arr = acne_list.filter(function (e) {
  200 + return e.type == 3;
200 201 })
201   - th.data.acne_num4=a_arr.length;
  202 + th.data.acne_num4 = a_arr.length;
202 203 let tab_arr = [{ id: 'zong_he', name: '综合肤质' }];
203   - if(pore_num) {
  204 + if (pore_num) {
204 205 tab_arr.push({ id: 'mao_kong', name: '毛孔' });
205 206 }
206   - if(blackhead_num){
  207 + if (blackhead_num) {
207 208 tab_arr.push({ id: 'hei_tou', name: '黑头' });
208 209 }
209   - if(speckle_num){
  210 + if (speckle_num) {
210 211 tab_arr.push({ id: 'se_ban', name: '色斑' });
211 212 }
212   - if(wrinkle_num){
  213 + if (wrinkle_num) {
213 214 tab_arr.push({ id: 'zhou_wen', name: '皱纹' });
214 215 }
215   - if(dark_type > -1) {
216   - tab_arr.push( { id: 'hei_yan_quan', name: '黑眼圈' });
  216 + if (dark_type > -1) {
  217 + tab_arr.push({ id: 'hei_yan_quan', name: '黑眼圈' });
217 218 }
218   - if(acne_num){
  219 + if (acne_num) {
219 220 tab_arr.push({ id: 'cuo_chuang', name: '痤疮' });
220 221 }
221   - tab_arr.push( { id: 'min_gan_du', name: '敏感度' });
  222 + tab_arr.push({ id: 'min_gan_du', name: '敏感度' });
222 223 th.setData({
223 224 acne_num: acne_num,
224 225 speckle_num: speckle_num,
225 226 wrinkle_num: wrinkle_num,
226   - wrinkle_types:wrinkle_types, //皱纹类型
  227 + wrinkle_types: wrinkle_types, //皱纹类型
227 228 blackhead_num: blackhead_num,
228 229 pore_num: pore_num,
229 230 dark_type: dark_type,
... ... @@ -231,30 +232,30 @@ Page({
231 232 dark_type2: dk_type2,
232 233 skin_sensitive_check: skin_sensitive_check,
233 234 skin_dryoil_check: skin_dryoil_check,
234   - skin_dryoil_check_type:skin_dryoil_check_type,
  235 + skin_dryoil_check_type: skin_dryoil_check_type,
235 236 face_img: img,
236   - m_top: (location.top-location.height/3)* bili,
237   - m_left:Math.abs(th.data.cWidth*0.8-(location.width+location.left*2)* bili)/2,
  237 + m_top: (location.top - location.height / 3) * bili,
  238 + m_left: Math.abs(th.data.cWidth * 0.8 - (location.width + location.left * 2) * bili) / 2,
238 239 bili: bili,
239   - bili_eye:bili_eye,
240   - sex:sex,
241   - tab:tab_arr,
242   - skin_dryoil_check_type:skin_dryoil_check_type,
243   - eye_top:eye_top* bili_eye,
244   - eye_left1:eye_left1* bili_eye,
245   - eye_left2:eye_left2* bili_eye,
246   -
247   - wrinkle_num1:th.data.wrinkle_num1, //抬头纹
248   - wrinkle_num2:th.data.wrinkle_num2, //川字纹
249   - wrinkle_num3:th.data.wrinkle_num3, //眼周细纹
250   - wrinkle_num4:th.data.wrinkle_num4, //鱼尾纹
251   - wrinkle_num5:th.data.wrinkle_num5, //法令纹
252   - wrinkle_num6:th.data.wrinkle_num6, //口周纹
253   -
254   - acne_num1:th.data.acne_num1, //粉刺
255   - acne_num2:th.data.acne_num2, //痘印
256   - acne_num3:th.data.acne_num3, //脓包
257   - acne_num4:th.data.acne_num4, //结节
  240 + bili_eye: bili_eye,
  241 + sex: sex,
  242 + tab: tab_arr,
  243 + skin_dryoil_check_type: skin_dryoil_check_type,
  244 + eye_top: eye_top * bili_eye,
  245 + eye_left1: eye_left1 * bili_eye,
  246 + eye_left2: eye_left2 * bili_eye,
  247 +
  248 + wrinkle_num1: th.data.wrinkle_num1, //抬头纹
  249 + wrinkle_num2: th.data.wrinkle_num2, //川字纹
  250 + wrinkle_num3: th.data.wrinkle_num3, //眼周细纹
  251 + wrinkle_num4: th.data.wrinkle_num4, //鱼尾纹
  252 + wrinkle_num5: th.data.wrinkle_num5, //法令纹
  253 + wrinkle_num6: th.data.wrinkle_num6, //口周纹
  254 +
  255 + acne_num1: th.data.acne_num1, //粉刺
  256 + acne_num2: th.data.acne_num2, //痘印
  257 + acne_num3: th.data.acne_num3, //脓包
  258 + acne_num4: th.data.acne_num4, //结节
258 259 })
259 260 var sort = 1;
260 261 //-- 调用毛孔的推荐函数 --
... ... @@ -275,7 +276,7 @@ Page({
275 276 //-- 黑眼圈 --
276 277 if (acne_num > -0)
277 278 acne.get_goods(th, setting.stoid, sort++);
278   -
  279 + sensitive.get_goods(th, setting.stoid, sort++);
279 280 //-- 获取一下分享要用的图片 --
280 281 th.set_share_img();
281 282 acne.get_goods(th, setting.stoid);
... ... @@ -319,7 +320,7 @@ Page({
319 320 }
320 321 })
321 322 },
322   -
  323 +
323 324  
324 325 //-- 初始等级卡 --
325 326 init: function () {
... ... @@ -486,11 +487,11 @@ Page({
486 487 })
487 488 },
488 489  
489   - close_yiwen(){
  490 + close_yiwen() {
490 491 this.setData({
491   - question_dialog:false,
492   - yiwen_index:0,
493   - yiwen_id:'yiwen1'
  492 + question_dialog: false,
  493 + yiwen_index: 0,
  494 + yiwen_id: 'yiwen1'
494 495 })
495 496 },
496 497  
... ... @@ -754,92 +755,92 @@ Page({
754 755 src: path3,
755 756 success: function (res) {
756 757  
757   - var b=1.1;
758   - //获取到二维码的图片
759   - var vpath = res.path;
760   - var context = wx.createCanvasContext('share');
761   - // 先画背景
762   - context.fillStyle = '#ebf6f8';
763   - // 灰色实心矩形
764   - // 1. 语法: x坐标, y坐标, 宽度, 高度
765   - context.fillRect(0,0,750 * rpx,1338 * rpx);
766   -
767   - context.setFontSize(20* rpx)
768   - context.setFillStyle("#00d8e9")
769   - context.fillText("官方检测认证", 28*b* rpx, 80*b* rpx);
770   -
771   - //两个底部颜色
772   - context.fillStyle = '#a7ecf5';
773   - context.fillRect(28 *b* rpx,136 *b* rpx,262 *b* rpx,18 *b* rpx);
774   - context.fillRect(28 *b* rpx,194 *b* rpx,262 *b* rpx,18 *b* rpx);
775   -
776   - context.setFontSize(42*b*rpx)
777   - context.setFillStyle("#070609")
778   - context.fillText("我的肌底强韧", 30*b* rpx, 140*b* rpx);
779   - context.fillText("肌肤鲜活润泽", 30*b* rpx, 196*b* rpx);
780   -
781   - //先画一个圆形
782   - th.circle(context,110*b*rpx, 280*b*rpx,140*b*rpx,"#e7f3f8");
783   - th.circle(context,130*b*rpx, 300*b*rpx,120*b*rpx,"#c8f2fa");
784   - //绘制人脸
785   - context.drawImage(th.data.share_head, 132*b*rpx, 310*b*rpx, 230*b* rpx, 230 *b* rpx);
786   -
787   - //左右俩个框并填充文字
788   - th.darwRoundRect(38 *b* rpx,340*b*rpx,140*b*rpx,40*b*rpx,20*b*rpx,context);
789   - th.darwRoundRect(324 *b* rpx,340*b*rpx,140*b*rpx,40*b*rpx,20*b*rpx,context);
790   - context.setFontSize(20*b*rpx)
791   - context.setFillStyle("black")
792   - context.fillText("黑眼圈 重度", 50*b* rpx, 368*b* rpx);
793   - context.fillText("毛孔 "+th.data.pore_num, 336*b* rpx, 368*b* rpx);
794   -
795   - //左右俩个框并填充文字
796   - th.darwRoundRect(40 *b* rpx,412*b*rpx,116*b*rpx,40*b*rpx,20*b*rpx,context);
797   - th.darwRoundRect(348 *b* rpx,412*b*rpx,116*b*rpx,40*b*rpx,20*b*rpx,context);
798   - context.setFillStyle("black")
799   - context.fillText("黑头 "+th.data.blackhead_num, 52*b* rpx, 440*b* rpx);
800   - context.fillText("色斑 "+th.data.speckle_num, 354*b* rpx, 440*b* rpx);
801   -
802   - //左右俩个框并填充文字
803   - th.darwRoundRect(60 *b* rpx,484*b*rpx,116*b*rpx,40*b*rpx,20*b*rpx,context);
804   - th.darwRoundRect(328 *b* rpx,484*b*rpx,116*b*rpx,40*b*rpx,20*b*rpx,context);
805   - context.setFillStyle("black")
806   - context.fillText("皱纹 "+th.data.wrinkle_num, 74*b* rpx, 510*b* rpx);
807   - context.fillText("痤疮 "+th.data.acne_num, 344*b* rpx, 510*b* rpx);
808   -
809   - //底部的绘制
810   - th.darwRoundRect(38 *b* rpx,650*b*rpx,430*b*rpx,160*b*rpx,10*b*rpx,context);
811   - //绘制二维码
812   - context.drawImage(vpath, 60*b*rpx, 672*b*rpx, 120 *b* rpx, 120 *b* rpx);
813   - context.setFillStyle("black")
814   - context.setFontSize(32*b*rpx)
815   - context.fillText("美肤管家AI测肤", 200*b* rpx, 726*b* rpx);
816   - context.setFontSize(22*b*rpx)
817   - context.fillText("科学了解皮肤的真实状态", 200*b* rpx, 766*b* rpx);
818   -
819   - //把画板内容绘制成图片,并回调 画板图片路径
820   - context.draw(false, function () {
821   - setTimeout(function () {
822   - wx.canvasToTempFilePath({
823   - x: 0,
824   - y: 0,
825   - width: 750,
826   - height: 1338,
827   - destWidth: 1.4 * 750 * 750 / th.data.screenWidth,
828   - destHeight: 1.4 * 750 * 750 / th.data.screenWidth,
829   - canvasId: 'share',
830   - success: function (res) {
831   - that.setData({
832   - shareImgPath: res.tempFilePath,
833   - canvasHidden: true,
834   - share_show:1
835   - })
836   - /*--
837   - wx.previewImage({
838   - //将图片预览出来
839   - ur--*/
840   -
841   - wx.hideLoading();
842   - }
  758 + var b = 1.1;
  759 + //获取到二维码的图片
  760 + var vpath = res.path;
  761 + var context = wx.createCanvasContext('share');
  762 + // 先画背景
  763 + context.fillStyle = '#ebf6f8';
  764 + // 灰色实心矩形
  765 + // 1. 语法: x坐标, y坐标, 宽度, 高度
  766 + context.fillRect(0, 0, 750 * rpx, 1338 * rpx);
  767 +
  768 + context.setFontSize(20 * rpx)
  769 + context.setFillStyle("#00d8e9")
  770 + context.fillText("官方检测认证", 28 * b * rpx, 80 * b * rpx);
  771 +
  772 + //两个底部颜色
  773 + context.fillStyle = '#a7ecf5';
  774 + context.fillRect(28 * b * rpx, 136 * b * rpx, 262 * b * rpx, 18 * b * rpx);
  775 + context.fillRect(28 * b * rpx, 194 * b * rpx, 262 * b * rpx, 18 * b * rpx);
  776 +
  777 + context.setFontSize(42 * b * rpx)
  778 + context.setFillStyle("#070609")
  779 + context.fillText("我的肌底强韧", 30 * b * rpx, 140 * b * rpx);
  780 + context.fillText("肌肤鲜活润泽", 30 * b * rpx, 196 * b * rpx);
  781 +
  782 + //先画一个圆形
  783 + th.circle(context, 110 * b * rpx, 280 * b * rpx, 140 * b * rpx, "#e7f3f8");
  784 + th.circle(context, 130 * b * rpx, 300 * b * rpx, 120 * b * rpx, "#c8f2fa");
  785 + //绘制人脸
  786 + context.drawImage(th.data.share_head, 132 * b * rpx, 310 * b * rpx, 230 * b * rpx, 230 * b * rpx);
  787 +
  788 + //左右俩个框并填充文字
  789 + th.darwRoundRect(38 * b * rpx, 340 * b * rpx, 140 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
  790 + th.darwRoundRect(324 * b * rpx, 340 * b * rpx, 140 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
  791 + context.setFontSize(20 * b * rpx)
  792 + context.setFillStyle("black")
  793 + context.fillText("黑眼圈 重度", 50 * b * rpx, 368 * b * rpx);
  794 + context.fillText("毛孔 " + th.data.pore_num, 336 * b * rpx, 368 * b * rpx);
  795 +
  796 + //左右俩个框并填充文字
  797 + th.darwRoundRect(40 * b * rpx, 412 * b * rpx, 116 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
  798 + th.darwRoundRect(348 * b * rpx, 412 * b * rpx, 116 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
  799 + context.setFillStyle("black")
  800 + context.fillText("黑头 " + th.data.blackhead_num, 52 * b * rpx, 440 * b * rpx);
  801 + context.fillText("色斑 " + th.data.speckle_num, 354 * b * rpx, 440 * b * rpx);
  802 +
  803 + //左右俩个框并填充文字
  804 + th.darwRoundRect(60 * b * rpx, 484 * b * rpx, 116 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
  805 + th.darwRoundRect(328 * b * rpx, 484 * b * rpx, 116 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
  806 + context.setFillStyle("black")
  807 + context.fillText("皱纹 " + th.data.wrinkle_num, 74 * b * rpx, 510 * b * rpx);
  808 + context.fillText("痤疮 " + th.data.acne_num, 344 * b * rpx, 510 * b * rpx);
  809 +
  810 + //底部的绘制
  811 + th.darwRoundRect(38 * b * rpx, 650 * b * rpx, 430 * b * rpx, 160 * b * rpx, 10 * b * rpx, context);
  812 + //绘制二维码
  813 + context.drawImage(vpath, 60 * b * rpx, 672 * b * rpx, 120 * b * rpx, 120 * b * rpx);
  814 + context.setFillStyle("black")
  815 + context.setFontSize(32 * b * rpx)
  816 + context.fillText("美肤管家AI测肤", 200 * b * rpx, 726 * b * rpx);
  817 + context.setFontSize(22 * b * rpx)
  818 + context.fillText("科学了解皮肤的真实状态", 200 * b * rpx, 766 * b * rpx);
  819 +
  820 + //把画板内容绘制成图片,并回调 画板图片路径
  821 + context.draw(false, function () {
  822 + setTimeout(function () {
  823 + wx.canvasToTempFilePath({
  824 + x: 0,
  825 + y: 0,
  826 + width: 750,
  827 + height: 1338,
  828 + destWidth: 1.4 * 750 * 750 / th.data.screenWidth,
  829 + destHeight: 1.4 * 750 * 750 / th.data.screenWidth,
  830 + canvasId: 'share',
  831 + success: function (res) {
  832 + that.setData({
  833 + shareImgPath: res.tempFilePath,
  834 + canvasHidden: true,
  835 + share_show: 1
  836 + })
  837 + /*--
  838 + wx.previewImage({
  839 + //将图片预览出来
  840 + ur--*/
  841 +
  842 + wx.hideLoading();
  843 + }
843 844 })
844 845 }, 500)
845 846  
... ...