1
2
3
4
5
6
7
8 Stringpath=request.getContextPath();9 intport=request.getServerPort();10 StringbasePath= null;11 if(port==80){12 basePath=request.getScheme()+"://"+request.getServerName()+path;13 }else{14 basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;15 }16 pageContext.setAttribute("basePath", basePath);17
18
19 Objectstr=request.getAttribute("face");20 JSONObject json=JSONObject.fromObject(str);21 JSONArray faces=json.getJSONArray("faces");22 StringBuffer strBuff= newStringBuffer();23 //识别出人脸的个数24 intlength=faces.size();25
26 //识别出多少个人脸,就是循环多少次27 for(inti= 0;i
29 JSONObject face=faces.getJSONObject(i);//拿到第i+1个人脸部信息30 JSONObject attribute=face.getJSONObject("attributes");//拿到脸部属性31
32 //年龄33 JSONObject age=attribute.getJSONObject("age");34 intageValue=age.getInt("value");35
36 //性别37 JSONObject gender=attribute.getJSONObject("gender");38 Stringsex=gender.getString("value");39 if(sex.equals("Male")) sex= "男";40 elsesex= "女";41
42 //人种43 JSONObject ethnicity=attribute.getJSONObject("ethnicity");44 Stringraces=ethnicity.getString("value");45 if(races.equals("Asian")) races= "亚洲人";46 else if(races.equals("White")) races= "白人";47 elseraces= "黑人";48
49 //微笑程度50 JSONObject smile=attribute.getJSONObject("smile");51 StringsmileRange= String.format("%.2f",smile.getDouble("value"));52
53 //表情54 JSONObject emotion=attribute.getJSONObject("emotion");55 Mapmapp= newTreeMap();56 //装配表情信息到map57 doublesadness=emotion.getDouble("sadness");58 mapp.put("伤心", sadness);59 doubleneutral=emotion.getDouble("neutral");60 mapp.put("平静", neutral);61 doubledisgust=emotion.getDouble("disgust");62 mapp.put("厌恶", disgust);63 doubleanger=emotion.getDouble("anger");64 mapp.put("愤怒", anger);65 doublehappiness=emotion.getDouble("happiness");66 mapp.put("高兴", happiness);67 doublesurprise=emotion.getDouble("surprise");68 mapp.put("惊讶", surprise);69 doublefear=emotion.getDouble("fear");70 mapp.put("恐惧", fear);71
72 //利用list取最大值73 Listlistmap= newArrayList();74 for(Stringkey:mapp.keySet()){75 listmap.add(mapp.get(key));76 }77 //取到最大值78 doublevalueMax=Collections.max(listmap);79 //根据map的value获取map的key80 StringemotionMax= "";81 for(Map.Entryentry : mapp.entrySet()) {82 if(valueMax==entry.getValue()){83 emotionMax=entry.getKey();84 }85 }86
87 //颜值分数88 JSONObject beauty=attribute.getJSONObject("beauty");89 Stringbeautys= "";90 if(sex.equals("男")) beautys= String.format("%.2f",beauty.getDouble("male_score"));91 elsebeautys= String.format("%.2f",beauty.getDouble("female_score"));92
93 //面部状态94 JSONObject skinstatus=attribute.getJSONObject("skinstatus");95 MapmapSkin= newTreeMap();96 //装配信息到map97 doublehealth=skinstatus.getDouble("health");98 mapSkin.put("健康指数",String.format("%.2f",health));99 doublestain=skinstatus.getDouble("stain");100 mapSkin.put("色斑指数",String.format("%.2f",stain));101 doubleacne=skinstatus.getDouble("acne");102 mapSkin.put("青春痘指数",String.format("%.2f",acne));103 doubledark_circle=skinstatus.getDouble("dark_circle");104 mapSkin.put("黑眼圈指数",String.format("%.2f",dark_circle));105
106 strBuff.append("
");107 strBuff.append("年龄:").append(ageValue).append("岁");108 strBuff.append("性别:").append(sex).append("");109 strBuff.append("
").append("
");110 strBuff.append("人种:").append(races+"");111 strBuff.append("微笑程度:").append(smileRange+"%");112 strBuff.append("
").append("
");113 strBuff.append("表情:").append(emotionMax+"");114 strBuff.append("颜值分数:").append(beautys+"");115 strBuff.append("
").append("
");116 intcounts= 0;117 for(Stringkey:mapSkin.keySet()){118 counts++;119 strBuff.append(""+key+":").append(mapSkin.get(key)+"");120 if(counts %2 == 0) strBuff.append("
").append("
");121 }122
123 strBuff.append("
");124
125 }126
127
128
129 %>
130
131
132
133
134
Java开发人脸特征识别系统 --krry135
136
137
138
139
140
141
142
143 *{padding:0px;margin:0px;}
144 body{background:#FFF;background:url("images/78788.jpg");background-size:cover;}
145 .a_btn{text-decoration:none;font-family:"幼圆";background:#fff;transition:.6s;color:#f60;cursor:pointer;width:100px;height:40px;border-radius:10px;display:inline-block;text-align:center;line-height:40px;}
146 .aa{position:absolute;left:48px;top:31px;}
147 .a_btn:hover{background:red;color:#fff;transition:.6s;}
148 .clear{clear:both;}
149 .title{margin-top:25px;font-size:48px;font-family:"幼圆";color:#ff7272;text-shadow:1px 1px 3px #ff3737;text-align:center;line-height:45px;}
150 .content{margin:0 auto;width:900px;}
151 .content .img{float:left;margin-top:30px;}
152 .content .img img{border-radius:10px;}
153 .content .describe{margin-top:30px;width:500px;color:#000;font-family:"幼圆";font-size:18px;float:right;}
154 .content .describe span{width:190px;display:inline-block;}
155
156
157
158
159
160 返回