開發與維運

Day2筆記——身份證識別系統搭建

一、獲取OCR的SDK的Maven座標(Java)
進入https://vision.aliyun.com/
通過文字識別中查看產品文檔,得知SDK支持包括Java、Java(本地接入)、Python、Node.js、PHP四種常用語言。通過檢索Java(支持本地上傳)的SDK,獲取OCR的Maven代碼(version=1.0.3):

<artifactId>ocr</artifactId>
<version>1.0.3</version>

二、框架分析
建立Springboot項目,Application為啟動類;Controller為控制器層,負責模板的渲染和路由等;Ocrservice負責通過SDK調用視覺識別的能力。上傳表單只允許後綴為.jpg,.jpeg,.png的文件,且不為空。
輸入限制:
·圖片格式:JPEG、JPG、PNG、BMP、GIF。
·圖像大小:圖像大小不超過3M。
·圖像分辨率:不限制圖片分辨率,但圖片分辨率太高可能會導致API識別超時,超時時間為5秒。
·URL地址中不能包含中文字符。
三、示例代碼

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.ocr.model.v20191230.*;

public class RecognizeIdentityCard {

public static void main(String[] args) {
    DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", "<accessKeyId>", "<accessSecret>");
    IAcsClient client = new DefaultAcsClient(profile);

    RecognizeIdentityCardRequest request = new RecognizeIdentityCardRequest();
    request.setRegionId("cn-shanghai");
    request.setSide("face");

    try {
        RecognizeIdentityCardResponse response = client.getAcsResponse(request);
        System.out.println(new Gson().toJson(response));
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (ClientException e) {
        System.out.println("ErrCode:" + e.getErrCode());
        System.out.println("ErrMsg:" + e.getErrMsg());
        System.out.println("RequestId:" + e.getRequestId());
    }

}
}

四、舉例示範
image.png
image.png

五、代碼展示:

五、總結
第二天的學習感覺很跨越,要通過Springboot框架開始調用SDK,進度有點跳躍,需要查閱資料,更近一步理解視頻講的專有術語和名詞。

Leave a Reply

Your email address will not be published. Required fields are marked *