Unity接入百度AI實(shí)現(xiàn)貨幣識(shí)別
接口介紹:
識(shí)別圖像中的貨幣類型,以紙幣為主,正反面均可準(zhǔn)確識(shí)別,接口返回貨幣的名稱、代碼、面值、年份信息;可識(shí)別各類近代常見貨幣,如美元、歐元、英鎊、法郎、澳大利亞元、俄羅斯盧布、日元、韓元、泰銖、印尼盧比等。
創(chuàng)建應(yīng)用:
在產(chǎn)品服務(wù)中搜索圖像識(shí)別,創(chuàng)建應(yīng)用,獲取AppID、APIKey、SecretKey信息:


查閱官方文檔,以下是貨幣識(shí)別接口返回?cái)?shù)據(jù)參數(shù)詳情:

定義數(shù)據(jù)結(jié)構(gòu):
using System;
/// <summary>
/// 貨幣識(shí)別
/// </summary>
[Serializable]
public class CurrencyRecognition
{
/// <summary>
/// 請(qǐng)求標(biāo)識(shí)碼,隨機(jī)數(shù),唯一
/// </summary>
public int log_id;
/// <summary>
/// 識(shí)別結(jié)果
/// </summary>
public CurrencyRecognitionResult result;
}
/// <summary>
/// 貨幣識(shí)別結(jié)果
/// </summary>
[Serializable]
public class CurrencyRecognitionResult
{
/// <summary>
/// 判斷是否返回詳細(xì)信息(除貨幣名稱之外的其他字段),含有返回1,不含有返回0
/// </summary>
public int hasdetail;
/// <summary>
/// 貨幣名稱,無(wú)法識(shí)別返回空
/// </summary>
public string currencyName;
/// <summary>
/// 貨幣代碼,hasdetail = 0時(shí),表示無(wú)法識(shí)別,該字段不返回
/// </summary>
public string currencyCode;
/// <summary>
/// 貨幣面值,hasdetail = 0時(shí),表示無(wú)法識(shí)別,該字段不返回
/// </summary>
public string currencyDenomination;
/// <summary>
/// 貨幣年份,hasdetail = 0時(shí),表示無(wú)法識(shí)別,該字段不返回
/// </summary>
public string year;
}
下載C# SDK:

下載完成后將AipSdk.dll動(dòng)態(tài)庫(kù)導(dǎo)入到Unity中:

以下是調(diào)用接口時(shí)傳入的參數(shù)詳情:

封裝調(diào)用函數(shù):
using System;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 圖像識(shí)別
/// </summary>
public class ImageRecognition
{
//以下信息于百度開發(fā)者中心控制臺(tái)創(chuàng)建應(yīng)用獲取
private const string appID = "";
private const string apiKey = "";
private const string secretKey = "";
/// <summary>
/// 貨幣識(shí)別
/// </summary>
/// <param name="bytes">圖片字節(jié)數(shù)據(jù)</param>
/// <returns></returns>
public static CurrencyRecognition Currency(byte[] bytes)
{
var client = new Baidu.Aip.ImageClassify.ImageClassify(apiKey, secretKey);
try
{
var response = client.Currency(bytes);
CurrencyRecognition currencyRecognition = JsonUtility.FromJson<CurrencyRecognition>(response.ToString());
return currencyRecognition;
}
catch (Exception error)
{
Debug.LogError(error);
}
return null;
}
/// <summary>
/// 貨幣識(shí)別
/// </summary>
/// <param name="url">圖片url地址</param>
/// <returns></returns>
public static CurrencyRecognition Currency(string url)
{
var client = new Baidu.Aip.ImageClassify.ImageClassify(apiKey, secretKey);
try
{
var response = client.CurrencyUrl(url);
CurrencyRecognition currencyRecognition = JsonUtility.FromJson<CurrencyRecognition>(response.ToString());
return currencyRecognition;
}
catch (Exception error)
{
Debug.LogError(error);
}
return null;
}
}
測(cè)試圖片:

using System.IO;
using UnityEngine;
public class Example : MonoBehaviour
{
private void Start()
{
ImageRecognition.Currency(File.ReadAllBytes(Application.dataPath + "/Picture.jpg"));
}
}
以上就是Unity接入百度AI實(shí)現(xiàn)貨幣識(shí)別的詳細(xì)內(nèi)容,更多關(guān)于Unity貨幣識(shí)別的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C#實(shí)現(xiàn)簡(jiǎn)單的Http請(qǐng)求實(shí)例
這篇文章主要介紹了C#實(shí)現(xiàn)簡(jiǎn)單的Http請(qǐng)求的方法,以實(shí)例形式較為詳細(xì)的分析了C#實(shí)現(xiàn)Http請(qǐng)求的具體方法,需要的朋友可以參考下2015-01-01
C# 使用Word模板導(dǎo)出數(shù)據(jù)的實(shí)現(xiàn)代碼
最近接到個(gè)需求,使用word模板導(dǎo)出數(shù)據(jù),怎么實(shí)現(xiàn)這個(gè)需求呢,今天小編通過(guò)實(shí)例代碼給大家介紹C# 使用Word模板導(dǎo)出數(shù)據(jù)的方法,感興趣的朋友一起看看吧2021-06-06
unity3D實(shí)現(xiàn)攝像機(jī)抖動(dòng)特效
這篇文章主要為大家詳細(xì)介紹了unity3D實(shí)現(xiàn)攝像機(jī)抖動(dòng)特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-01-01
C#中把任意類型的泛型集合轉(zhuǎn)換成SQLXML數(shù)據(jù)格式的實(shí)例
本文主要分享了C#中把任意類型的泛型集合轉(zhuǎn)換成SQLXML數(shù)據(jù)格式的實(shí)例代碼。具有很好的參考價(jià)值,需要的朋友可以看下2016-12-12
C#使用Socket實(shí)現(xiàn)發(fā)送和接收?qǐng)D片的方法
這篇文章主要介紹了C#使用Socket實(shí)現(xiàn)發(fā)送和接收?qǐng)D片的方法,涉及C#操作socket發(fā)送與接收文件的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04
C#郵件定時(shí)群發(fā)工具Atilia用法實(shí)例
這篇文章主要介紹了C#郵件定時(shí)群發(fā)工具Atilia用法,較為詳細(xì)的分析了Atilia實(shí)現(xiàn)郵件定時(shí)群發(fā)功能的原理與實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
C# Winform實(shí)現(xiàn)導(dǎo)入和導(dǎo)出Excel文件
這篇文章主要為大家詳細(xì)介紹了C# Winform實(shí)現(xiàn)導(dǎo)入和導(dǎo)出Excel文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12

