一、擷取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());
}
}
}
四、舉例示範

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