阅读444 返回首页    go iPhone_iPad_Mac_手机_平板_苹果apple


门店识别__API介绍_文字识别_人工智能图像类-阿里云

本页面主要介绍服务对应的接口和返回结果中的关键字段的含义,请在阅读本页面之前,了解请求数据格式介绍,了解输入输出的通用数据格式。 此外,在本页最后,附上了门店招牌识别服务调用的程序示例,以供参考。

请求接口

  • 云市场接口

    • 请求方法: POST
    • 请求url: 在云市场搜索印刷文字识别-门店识别,在API接口中找到调用地址
  • 数加接口

    • 请求方法: POST
    • 请求url: 打开管理控制台,接口名称选择ocr_shop_sign,查看请求地址

请求参数格式

参数名称 参数类型 描述 默认值
image string dataType为50, dataValue是base64编码后的图像数据 空字符串

http post请求的Body示例如下:

  1. {
  2. "inputs": [
  3. {
  4. "image": {
  5. "dataType": 50, #50表示image的数据类型为字符串
  6. "dataValue": "base64_image_string" #图片以base64编码的string
  7. }
  8. }]
  9. }

返回结果格式

返回结果仅包含两个字段:

  • shop_sign: 检测到并且识别出的门店招牌名称, 类型为字符串
  • success: 识别过程是否成功完成,true表示成功完成, false表示失败, 类型为布尔型
  1. {
  2. "outputs": [
  3. {
  4. "outputLabel": "ocr_shop_sign",
  5. "outputMulti": {},
  6. "outputValue": {
  7. "dataType": 50,
  8. "dataValue": "{
  9. "shop_sign" : "脆皮烤鸭", #识别字符
  10. "success": true #识别结果:true表示成功,false表示失败
  11. }"
  12. }
  13. }]
  14. }

程序示例

云市场

云市场搜索印刷文字识别-门店识别,在API接口中找到请求示例

数加平台

  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import org.apache.commons.codec.binary.Base64;
  5. import org.json.JSONObject;
  6. import org.json.JSONArray;
  7. import org.json.JSONException;
  8. public class Shop {
  9. /*
  10. * 获取参数的json对象
  11. */
  12. public static JSONObject getParam(int type, JSONObject dataValue) {
  13. JSONObject obj = new JSONObject();
  14. try {
  15. obj.put("dataType", type);
  16. obj.put("dataValue", dataValue);
  17. } catch (JSONException e) {
  18. e.printStackTrace();
  19. }
  20. return obj;
  21. }
  22. /*
  23. * 获取参数的json对象
  24. */
  25. public static JSONObject getParam(int type, String dataValue) {
  26. JSONObject obj = new JSONObject();
  27. try {
  28. obj.put("dataType", type);
  29. obj.put("dataValue", dataValue);
  30. } catch (JSONException e) {
  31. e.printStackTrace();
  32. }
  33. return obj;
  34. }
  35. public static void main(String[] args) {
  36. String imgFile = "shop.jpg";
  37. String serviceURL = "your-service-url";
  38. String akID = "your access key id";
  39. String akSecret = "your access key secret";
  40. // 对图像进行base64编码
  41. String imgBase64 = "";
  42. try {
  43. File file = new File(imgFile);
  44. byte[] content = new byte[(int) file.length()];
  45. FileInputStream finputstream = new FileInputStream(file);
  46. finputstream.read(content);
  47. finputstream.close();
  48. imgBase64 = new String(Base64.encodeBase64(content));
  49. } catch (IOException e) {
  50. e.printStackTrace();
  51. return;
  52. }
  53. // 拼装请求body的json字符串
  54. JSONObject requestObj = new JSONObject();
  55. try {
  56. JSONObject obj = new JSONObject();
  57. JSONArray inputArray = new JSONArray();
  58. obj.put("image", getParam(50, imgBase64));
  59. inputArray.put(obj);
  60. requestObj.put("inputs", inputArray);
  61. } catch (JSONException e) {
  62. e.printStackTrace();
  63. }
  64. String body = requestObj.toString();
  65. //Sender代码参考 https://help.aliyun.com/document_detail/shujia/OCR/ocr-api/sender.html
  66. String result = Sender.sendPost(serviceURL, body, akID, akSecret);
  67. System.out.println(result);
  68. // 解析请求结果
  69. try {
  70. JSONObject resultObj = new JSONObject(result);
  71. JSONArray outputArray = resultObj.getJSONArray("outputs");
  72. String output = outputArray.getJSONObject(0).getJSONObject("outputValue").getString("dataValue"); // 取出结果json字符串
  73. JSONObject out = new JSONObject(output);
  74. if (out.getBoolean("success")) {
  75. String shop_sign = out.getString("shop_sign"); // 获取门店
  76. System.out.printf(" shop_name : %s n", shop_sign);
  77. } else {
  78. System.out.println("predict error");
  79. }
  80. } catch (JSONException e) {
  81. e.printStackTrace();
  82. }
  83. }
  84. }

最后更新:2016-11-24 11:23:48

  上一篇:go 营业执照识别__API介绍_文字识别_人工智能图像类-阿里云
  下一篇:go 英文识别__API介绍_文字识别_人工智能图像类-阿里云