• 人脸识别&ORC的Demo


    一.用到的jar包:

    face_sdk-1.3.4.jar

    json-20160810.jar

    ocr_sdk-1.3.4.jar

    下载地址:https://files.cnblogs.com/files/DreamDrive/ocrdemo.rar

    二.测试代码

    FaceDetect.java

     1 import java.util.HashMap;
     2 
     3 import org.json.JSONObject;
     4 
     5 import com.baidu.aip.face.AipFace;
     6 /**
     7  * 百度云人脸检测demo
     8  * @author Administrator
     9  *
    10  */
    11 public class FaceDetect {
    12 
    13     private static AipFace apiFace=null;
    14     final static String APP_ID="9662379";
    15     final static String AIP_KEY="BGczNjdkZs5UQxUBlHzDWP6R";
    16     final static String AIP_TOKEN="lLL5C2nItGPnuXME2GM2PzfDRNtrCkRi";
    17     static {
    18         if(apiFace==null){
    19             apiFace=new AipFace(APP_ID,AIP_KEY,AIP_TOKEN);
    20         }
    21     }
    22     public void faceDetect(String path){
    23         HashMap<String,String> options=new HashMap<String,String>();
    24         options.put("max_face_num", "5");
    25         JSONObject response = apiFace.detect(path,options);
    26         System.out.println(response.toString());
    27 
    28         // 参数为本地图片文件二进制数组
    29 //        byte[] file = readImageFile(path);    // readImageFile函数仅为示例
    30 //        JSONObject response = apiFace.detect(file,options);
    31 //        System.out.println(response.toString());
    32     }
    33     
    34     public static void main(String[] args){
    35         new FaceDetect().faceDetect("n:/timg3.jpg");
    36     }
    37 }

    OcrDemo.java

     1 import java.util.HashMap;
     2 import org.json.JSONObject;
     3 import com.baidu.aip.ocr.AipOcr;
     4 public class OcrDemo {
     5 
     6     
     7     //设置APPID/AK/SK
     8     public static final String APP_ID = "9695214";
     9     public static final String API_KEY = "HxqwTu1M85G1UrG9DZKTNQzN";
    10     public static final String SECRET_KEY = "GVy7ah7MTRUczxS4hCuUvfCCV8oloRZX";
    11 
    12     public static void main(String[] args) {
    13         // 初始化一个OcrClient
    14         AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
    15 
    16         // 可选:设置网络连接参数
    17         client.setConnectionTimeoutInMillis(2000);
    18         client.setSocketTimeoutInMillis(60000);
    19         HashMap<String, String> params=new HashMap<String,String>();
    20         // 调用身份证识别接口
    21         String idFilePath = "n:/shenfenzheng1.jpg";
    22         JSONObject idcardRes = client.idcard(idFilePath, true,params);
    23         System.out.println(idcardRes.toString(2));
    24 
    25         // 调用银行卡识别接口
    26         String bankFilePath = "n:/bankcard.png";
    27         JSONObject bankRes = client.bankcard(bankFilePath);
    28         System.out.println(bankRes.toString(2));
    29 
    30         // 调用通用识别接口
    31         String genFilePath = "n:/words.png";
    32         JSONObject genRes = client.basicGeneral(genFilePath, new HashMap<String, String>());
    33         System.out.println(genRes.toString(2));
    34 
    35         // 调用通用识别(含位置信息)接口
    36 //        String genFilePath = "test_general.jpg";
    37 //        JSONObject genRes = client.general(genFilePath, new HashMap<String, String>());
    38 //        System.out.println(genRes.toString(2));
    39     }
    40 }
  • 相关阅读:
    leetcode-409
    leetcode-836
    leetcode-1160
    leetcode-面试题13
    leetcode-695
    go的一些小lib
    leetcode-300
    cookie
    php上传文件
    PHP 文件创建/写入
  • 原文地址:https://www.cnblogs.com/DreamDrive/p/7603731.html
Copyright © 2020-2023  润新知