本文主要介绍了如何通过Unity实现红酒识别,可以实现识别图像中的红酒标签,返回红酒名称、国家、产区、酒庄、类型、糖分、葡萄品种、酒品描述等信息,感兴趣的可以学习一下
接口介绍:
识别图像中的红酒标签,返回红酒名称、国家、产区、酒庄、类型、糖分、葡萄品种、酒品描述等信息,可识别数十万中外红酒;支持自定义红酒图库,在自建库中搜索特定红酒信息。
创建应用:
在产品服务中搜索图像识别,创建应用,获取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"));
}
}
到此这篇关于Unity实现红酒识别的示例代码的文章就介绍到这了,更多相关Unity红酒识别内容请搜索得得之家以前的文章希望大家以后多多支持得得之家!
织梦狗教程
本文标题为:Unity实现红酒识别的示例代码


基础教程推荐
猜你喜欢
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- C#中 Json 序列化去掉null值的方法 2022-11-18
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- C#中的Linq to JSON操作详解 2023-06-08
- C# 解析XML和反序列化的示例 2023-04-14
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- 实例详解C#实现http不同方法的请求 2022-12-26
- Unity shader实现高斯模糊效果 2023-01-16
- C#调用摄像头实现拍照功能的示例代码 2023-03-09