zoukankan      html  css  js  c++  java
  • java实现人脸识别V3版本开发

          有段时间没有写更新公众号了,也许好多人都忘记了自己还关注了这么个公众号。

           

        因为这段时间确实是有其他的事比较忙,还有一个原因就是自己在技术方面没有学习新的东西,所以没有可更新的(包括博客)

        今天,我决定更新一下,内容主要为:java实现人脸识别使用百度API接口V3版本,主要功能实现了人脸注册,人脸搜索(人脸登陆),人脸检测

            以前做出来的是V2版本的,那是207年的事了,时隔2018年一年,为什么现在才更新呢,这里我解释一下,说实话,我存在点私心,因为V2版本的代码只能v2的key来完成,而百度方面升级了之后用户创建的均为V3的key。我以前写的代码(博客里面的代码)都是v2的代码,其他人要想测试效果只能从我这要key,我会让他们关注我的公众号获取(因为当时做人脸识别的时候费了好多精力,不想一下子就分享给别人),所以通过这种简单的交易来成全双方的。

        现在我想重新开发v3的版本,在分享给别人,取长补短,使得自己的技术更能得到提升,故此公开v3的源码:

    人脸检测:

    public static void face_jiance(AipFace client) { 

        // 传入可选参数调用接口

        HashMap<String, String> options = new HashMap<String, String>();

        options.put("face_field", "age");

        options.put("max_face_num", "2");

        options.put("face_type", "LIVE");

        File directory = new File("");// 参数为空

            String courseFile="";

    try {

    courseFile = directory.getCanonicalPath();

    //获取当前项目的根路径

            //System.out.println(courseFile);

        String image = courseFile+"/WebRoot/picture/111.jpg";

        String imageType = "BASE64";

        //转换格式

        String strImageToBase64 =ImageToBase64(image);

        //输出base64图像数据

            //System.out.println("本地图片转换Base64:"+strImageToBase64);

        // 人脸检测

        JSONObject res = client.detect(strImageToBase64,imageType, options);

        System.out.println(res.toString(2));

    } catch (IOException e) {

    // TODO 异常执行块!

    e.printStackTrace();

    }

    }

    人脸注册:

    public static void face_reg(AipFace client) {

        // 传入可选参数调用接口

        HashMap<String, String> options = new HashMap<String, String>();

        options.put("user_info", "user's info");

        String groupId = "group1";

        String userId = "user1";

        File directory = new File("");// 参数为空

            String courseFile="";

    try {

    courseFile = directory.getCanonicalPath();

    //获取当前项目的根路径

            //System.out.println(courseFile);

    String image = courseFile+"/WebRoot/picture/111.jpg";

    String imageType = "BASE64";

        //转换格式

        String strImageToBase64 =ImageToBase64(image);

        //输出base64图像数据

            //System.out.println("本地图片转换Base64:"+strImageToBase64);

        // 人脸注册

        JSONObject res = client.addUser(strImageToBase64, imageType, groupId, userId, options);

        System.out.println(res.toString(2));

        

    } catch (IOException e) {

    // TODO 异常执行块!

    e.printStackTrace();

    }

    }

    人脸登陆:

    public static void face_login(AipFace client) {

        // 传入可选参数调用接口

        HashMap<String, String> options = new HashMap<String, String>();

        options.put("user_id", "user1");

        File directory = new File("");// 参数为空

            String courseFile="";

            String groupIdList = "group1";

    try {

    courseFile = directory.getCanonicalPath();

    //获取当前项目的根路径

            //System.out.println(courseFile);

    String image = courseFile+"/WebRoot/picture/222.jpg";

    String imageType = "BASE64";

        //转换格式

        String strImageToBase64 =ImageToBase64(image);

        //输出base64图像数据

            //System.out.println("本地图片转换Base64:"+strImageToBase64);

        // 人脸搜索

        JSONObject res = client.search(strImageToBase64, imageType, groupIdList, options);

        System.out.println(res.toString(2));

        

    } catch (IOException e) {

    // TODO 异常执行块!

    e.printStackTrace();

    }

    }

  • 相关阅读:
    curl发送post请求,统计响应时间
    云集微店、拼多多等顽疾凸显,社交电商如何突围?
    App音频内录 录音
    nginx支持android、ios、微信扫一扫
    hadoop 2.7.1安装和配置
    Centos7上HBase的安装和配置
    HBase各版本对Hadoop版本的支持情况
    40个Java多线程问题总结
    JAVA多线程之volatile 与 synchronized 的比较
    深入解析spring中用到的九种设计模式
  • 原文地址:https://www.cnblogs.com/a1111/p/14877507.html
Copyright © 2011-2022 走看看