閱讀534 返回首頁    go 阿裏雲 go 技術社區[雲棲]


行駛證識別__API介紹_文字識別_人工智能圖像類-阿裏雲

本頁麵主要介紹服務對應的接口和返回結果中的關鍵字段的含義,請在閱讀本頁麵之前,了解請求數據格式介紹,了解輸入輸出的通用數據格式。 此外,在本頁最後,附上了駕駛證識別服務調用的程序示例,以供參考。

請求接口

  • 雲市場接口

    • 請求方法: POST
    • 請求url: 在雲市場搜索印刷文字識別-行駛證識別,在API接口中找到調用地址
  • 數加接口

    • 請求方法: POST
    • 請求url: 打開管理控製台,接口名稱選擇ocr_vehicle_license,查看請求地址

請求參數

參數名稱 參數類型 描述 默認值
image string dataType為50, dataValue是base64編碼後的圖像數據 空字符串

POST請求body 示例如下:

  1. {
  2. "inputs": [
  3. {
  4. "image": {
  5. "dataType": 50, #50表示image的數據類型為字符串
  6. "dataValue": "base64_image_string" #圖片以base64編碼的string
  7. }
  8. }]
  9. }

返回結果格式

返回結果格式如下:

  1. {
  2. "outputs": [
  3. {
  4. "outputLabel": "ocr_vehicle_license",
  5. "outputMulti": {},
  6. "outputValue": {
  7. "dataType": 50,
  8. "dataValue": "{
  9. "config_str": "", #配置字符串信息
  10. "owner": "張三", #所有人名稱
  11. "plate_num": "滬A0M084", #車牌號碼
  12. "model":"奧德賽HG7420", #品牌型號
  13. "vin" : "LSVFF66R8C2116280", #車輛識別代號
  14. "engine_num" : "416098", #發動機號碼
  15. "register_date": "20121127", #注冊日期
  16. "request_id": "84701974fb983158_20160526100112", #請求對應的唯一表示
  17. "success": true #識別成功與否 true/false
  18. }"
  19. }
  20. }]
  21. }

每一個請求返回的結果都是一個json字符串,由dataValue關鍵詞可以索引到,主要有如下字段:

  • config_str: 表示發送請求時候的配置字符串,為json字符串格式,表示輸入時候的配置參數, 類型為字符串
  • owner: 所有人名稱, 類型為字符串
  • plate_num: 車牌號碼, 類型為字符串
  • model: 品牌型號, 類型為字符串
  • vin: 車輛識別代號, 類型為字符串
  • engine_num: 發動機號碼, 類型為字符串
  • register_date: 注冊日期, 類型為字符串
  • request_id: 請求對應的唯一表示, 用戶可以保存該字段用以進行問題追溯,類型為字符串
  • success: 識別流程是否出現異常, false表示識別失敗,true表示識別成功, 類型為布爾型

程序示例

雲市場

在雲市場搜索印刷文字識別-行駛證識別,在API接口中找到請求示例

數加平台

  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import sun.misc.BASE64Encoder;
  5. import org.json.JSONObject;
  6. import org.json.JSONArray;
  7. import org.json.JSONException;
  8. @SuppressWarnings("restriction")
  9. public class vehicle {
  10. /*
  11. * 獲取參數的json對象
  12. */
  13. public static JSONObject getParam(int type, JSONObject dataValue) {
  14. JSONObject obj = new JSONObject();
  15. try {
  16. obj.put("dataType", type);
  17. obj.put("dataValue", dataValue);
  18. } catch (JSONException e) {
  19. e.printStackTrace();
  20. }
  21. return obj;
  22. }
  23. /*
  24. * 獲取參數的json對象
  25. */
  26. public static JSONObject getParam(int type, String dataValue) {
  27. JSONObject obj = new JSONObject();
  28. try {
  29. obj.put("dataType", type);
  30. obj.put("dataValue", dataValue);
  31. } catch (JSONException e) {
  32. e.printStackTrace();
  33. }
  34. return obj;
  35. }
  36. public static void main(String[] args) {
  37. String img_file = "vehicle.jpg";
  38. String service_url = "your-service-url";
  39. String ak_id = "your access key id";
  40. String ak_secret = "your access key secret";
  41. // 對圖像進行base64編碼
  42. String img_base64 = "";
  43. try {
  44. File file = new File(img_file);
  45. byte[] content = new byte[(int) file.length()];
  46. FileInputStream finputstream = new FileInputStream(file);
  47. finputstream.read(content);
  48. finputstream.close();
  49. img_base64 = (new BASE64Encoder()).encode(content);
  50. } catch (IOException e) {
  51. e.printStackTrace();
  52. return;
  53. }
  54. // 拚裝請求body的json字符串
  55. JSONObject request_obj = new JSONObject();
  56. try {
  57. JSONObject obj = new JSONObject();
  58. JSONArray input_array = new JSONArray();
  59. obj.put("image", getParam(50, img_base64));
  60. input_array.put(obj);
  61. request_obj.put("inputs", input_array);
  62. } catch (JSONException e) {
  63. e.printStackTrace();
  64. }
  65. String body = request_obj.toString();
  66. //Sender代碼參考 https://help.aliyun.com/document_detail/shujia/OCR/ocr-api/sender.html
  67. String result = Sender.sendPost(service_url, body, ak_id, ak_secret);
  68. System.out.println(result);
  69. // 解析請求結果
  70. try {
  71. JSONObject result_obj = new JSONObject(result);
  72. JSONArray output_array = result_obj.getJSONArray("outputs");
  73. String output = output_array.getJSONObject(0).getJSONObject("outputValue").getString("dataValue"); // 取出結果json字符串
  74. JSONObject out = new JSONObject(output);
  75. if (out.getBoolean("success")) {
  76. String owner = out.getString("owner"); // 獲取所有人
  77. String plate_num = out.getString("plate_num"); // 獲取車牌號碼
  78. String model_type = out.getString("model"); // 獲取品牌型號
  79. String vin = out.getString("vin"); // 獲取車輛識別代碼
  80. String engine_num = out.getString("engine_num"); // 獲取發動機號碼
  81. String register_date = out.getString("register_date"); // 獲取注冊日期
  82. String request_id = out.getString("request_id"); // 獲取request_id
  83. System.out.printf(" owner : %s n plate_num : %sn model_type : %sn vin : %sn engine_num : %sn register_date : %sn request_id : %sn", owner, plate_num, model_type,
  84. vin, engine_num, register_date, request_id);
  85. } else {
  86. System.out.println("predict error");
  87. }
  88. } catch (JSONException e) {
  89. e.printStackTrace();
  90. }
  91. }
  92. }

最後更新:2016-11-23 16:04:15

  上一篇:go 駕駛證識別__API介紹_文字識別_人工智能圖像類-阿裏雲
  下一篇:go 營業執照識別__API介紹_文字識別_人工智能圖像類-阿裏雲