阅读534 返回首页    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介绍_文字识别_人工智能图像类-阿里云