源由
意外发现了学校某个系统的漏洞,可以不鉴权查看考生的照片 。所以我通过一段java代码将这些照片给下载到电脑上 。当我看到这些照片的时候 , 另一个想法便出现了,就是利用目前的人脸识别技术给这些照片来打个分 。
人脸识别
人脸识别
人脸识别
操作流程
注册百度智能云账户
在:产品服务 / 人脸识别 里,建立一个自己的应用
打开官方文档,根据步骤操作,重要的是你需要把代码里的APP_ID,API_KEY,SECRET_KEY替换成你自己的 , 这些是在你步骤2的时候创建成功就能看见 。
完成上述三步,即可以开始测试了 。通常测试的图片需要转成base64编码,所以此时可以利用Java的IO方法读取硬盘里的图片和Java自带方法BASE64Encoder对图片进行编码.
程序运行流程
开始遍历文件夹内图片读取文件并Base64编码人脸识别接收人脸识别的信息删除不需要的信息保存信息到txt文件是否遍历完成?结束yesno
读取硬盘图片以及转换成base64编码的代码:
public String getImgBase64(String filePath) { byte[] data = https://baike.zhangchenghui.com/269280/null; try { InputStream in = new FileInputStream(filePath); data = new byte[in.available()]; in.read(data); in.close(); } catch (IOException e) { e.printStackTrace(); } BASE64Encoder encoder = new BASE64Encoder(); // System.err.println(encoder.encode(data)); return encoder.encode(data); }
人脸识别数据写入到txt内:
public void appendJson(String str, String filePath) { BufferedWriter bw = null; try { bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath, true))); bw.write(str + "\r\n"); } catch (Exception e) { e.printStackTrace(); } finally { try { bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } } }
程序的主体:
//设置APPID/AK/SK public static final String APP_ID = "你的 App ID"; public static final String API_KEY = "你的 Api Key"; public static final String SECRET_KEY = "你的 Secret Key"; public static void main(String[] args) { feceServerImpl faceServer = new feceServerImpl(); // 初始化一个AipFace AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY); Map
msg = new HashMap
(); // 可?。荷柚猛缌硬问?client.setConnectionTimeoutInMillis(2000); client.setSocketTimeoutInMillis(60000); // 可?。荷柚么矸衿鞯刂? http和socket二选一,或者均不设置 // client.setHttpProxy("proxy_host", proxy_port); // 设置http代理 // client.setSocketProxy("proxy_host", proxy_port); // 设置socket代理 // 遍历指定文件夹 String path = "E:\\downloadImg\\"; File file = new File(path); File[] files = file.listFiles(); for (File f : files) { if (!f.isDirectory()) { // 调用接口 String image = faceServer.getImgBase64(f.toString()); // 指定图片的类型 String imageType = "BASE64"; // 传入可选参数调用接口 HashMap
options = new HashMap
(); // 这个是指定服务器返回的参数 , 其中age代表要检测年龄;beauty是检测颜值 options.put("face_field", "age,beauty"); options.put("max_face_num", "1"); options.put("face_type", "CERT"); // 人脸检测 JSONObject res = client.detect(image, imageType, options); // 将服务器返回的数据转成map,方便操作 Map
stringObjectMap = res.toMap(); // 删除不必要的数据 stringObjectMap.remove("log_id"); stringObjectMap.remove("error_msg"); stringObjectMap.remove("cached"); stringObjectMap.remove("error_code"); stringObjectMap.remove("timestamp"); // 添加照片的名字到map里,方便知道这条数据对应的哪张照片 stringObjectMap.put("照片", f.toString()); System.out.println(res.toString(1)); // 将评分数据写入到txt文件内 faceServer.appendJson(stringObjectMap.toString(), "e:\\imgJson.txt"); // 防止QPS超限,进行延迟 try { Thread.currentThread().sleep(500);//毫秒 } catch (Exception e) { e.printStackTrace(); } //break; } } }
服务器返回的JSON数据:
{ "result": { "face_num": 1, "face_list": [{ "beauty": 67.85, "angle": { "roll": -2.2, "pitch": 9.88, "yaw": -2.92 }, "face_token": "e5605d71d9122dab83aa8d", "location": { "top": 232.71, "left": 146.96, "rotation": 0, "width": 257, "height": 246 }, "face_probability": 1, "age": 22 }] }, "log_id": 134505071801, "error_msg": "SUCCESS", "cached": 0, "error_code": 0, "timestamp": 1561809237}
整理数据
将由代码保存的到硬盘txt文本数据,复制到Excel里借用排序工具进行整理,便可以知道哪张图片的颜值最高 。最终整理的数据如下图:
最终数据
【人脸识别分析五官测试 姓名测试打分最准免费】
-- 展开阅读全文 --
推荐阅读
- 孕期经常感冒为什么
- nellie英文名什么意思 nei是什么意思
- 特别瘦的男生健身多久能增肌 肌肉多久能练出来
- 狮子座在一起久了会怎么样 狮子养久了会认主人吗
- 晚上梦见一直在逃命 梦见跟着很多人在逃命
- 什么卷发显脸小 酒红色搭配碎刘海
- 梦见自己怀孕什么征兆 梦见自己老婆生孩子有啥征兆
- 单眼皮女生适合什么发型 鬼怪池恩卓金高银高中生发型
- 做噩梦梦到死了好多人 梦见自己马上要死了
