赞
踩
接口介绍:
识别图像中的红酒标签,返回红酒名称、国家、产区、酒庄、类型、糖分、葡萄品种、酒品描述等信息,可识别数十万中外红酒;支持自定义红酒图库,在自建库中搜索特定红酒信息。
创建应用:
在产品服务中搜索图像识别,创建应用,获取AppID、APIKey、SecretKey信息:
查阅官方文档,以下是红酒识别接口返回数据参数详情:
定义数据结构:
- using System;
-
- [Serializable]
- public class RedwineRecognition
- {
- /// <summary>
- /// 请求标识码,随机数,唯一
- /// </summary>
- public float log_id;
- /// <summary>
- /// 识别结果
- /// </summary>
- public RedwineRecognitionResult result;
- }
-
- /// <summary>
- /// 识别结果
- /// </summary>
- [Serializable]
- public class RedwineRecognitionResult
- {
- /// <summary>
- /// 判断是否返回详细信息(除红酒中文名之外的其他字段),含有返回1,不含有返回0
- /// </summary>
- public int hasdetail;
- /// <summary>
- /// 红酒中文名,无法识别返回空
- /// </summary>
- public string wineNameCn;
- /// <summary>
- /// 红酒英文名,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string wineNameEn;
- /// <summary>
- /// 国家中文名,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string countryCn;
- /// <summary>
- /// 国家英文名,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string countryEn;
- /// <summary>
- /// 产区中文名,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string regionCn;
- /// <summary>
- /// 产区英文名,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string regionEn;
- /// <summary>
- /// 子产区中文名,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string subRegionCn;
- /// <summary>
- /// 子产区英文名,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string subRegionEn;
- /// <summary>
- /// 酒庄中文名,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string wineryCn;
- /// <summary>
- /// 酒庄英文名,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string wineryEn;
- /// <summary>
- /// 酒类型,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string classifyByColor;
- /// <summary>
- /// 糖分类型,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string classifyBySugar;
- /// <summary>
- /// 色泽,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string color;
- /// <summary>
- /// 葡萄品种,可能有多种葡萄,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string grapeCn;
- /// <summary>
- /// 葡萄品种英文名,可能有多种葡萄,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string grapeEn;
- /// <summary>
- /// 品尝温度,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string tasteTemperature;
- /// <summary>
- /// 酒品描述,hasdetail = 0时,表示无法识别,该字段不返回
- /// </summary>
- public string description;
- }
下载C# SDK:
下载完成后将AipSdk.dll动态库导入到Unity中:
以下是调用接口时传入的参数详情:
封装调用函数:
- using System;
- using System.Collections.Generic;
- using UnityEngine;
-
- /// <summary>
- /// 图像识别
- /// </summary>
- public class ImageRecognition
- {
- //以下信息于百度开发者中心控制台创建应用获取
- private const string appID = "";
- private const string apiKey = "";
- private const string secretKey = "";
-
- /// <summary>
- /// 红酒识别
- /// </summary>
- /// <param name="bytes">图片字节数据</param>
- /// <returns></returns>
- public static RedwineRecognition Redwine(byte[] bytes)
- {
- var client = new Baidu.Aip.ImageClassify.ImageClassify(apiKey, secretKey);
- try
- {
- var response = client.Redwine(bytes);
- RedwineRecognition redwineRecognition = JsonConvert.DeserializeObject<RedwineRecognition>(response.ToString());
- return redwineRecognition;
- }
- catch (Exception error)
- {
- Debug.LogError(error);
- }
- return null;
- }
- /// <summary>
- /// 红酒识别
- /// </summary>
- /// <param name="url">图片url地址</param>
- /// <returns></returns>
- public static RedwineRecognition Redwine(string url)
- {
- var client = new Baidu.Aip.ImageClassify.ImageClassify(apiKey, secretKey);
- try
- {
- var response = client.RedwineUrl(url);
- RedwineRecognition redwineRecognition = JsonConvert.DeserializeObject<RedwineRecognition>(response.ToString());
- return redwineRecognition;
- }
- catch (Exception error)
- {
- Debug.LogError(error);
- }
- return null;
- }
- }
测试图片:
- using System.IO;
- using UnityEngine;
-
- public class Example : MonoBehaviour
- {
- private void Start()
- {
- ImageRecognition.Redwine(File.ReadAllBytes(Application.dataPath + "/Picture.jpg"));
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。