欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity接入百度AI實(shí)現(xiàn)貨幣識(shí)別

 更新時(shí)間:2022年01月04日 10:05:51   作者:CoderZ1010  
本文主要介紹了在Unity中接入百度AI,從而實(shí)現(xiàn)貨幣識(shí)別,可以返回貨幣的名稱、代碼、面值、年份信息等,感興趣的可以跟隨小編學(xué)習(xí)一下

接口介紹:

識(shí)別圖像中的貨幣類型,以紙幣為主,正反面均可準(zhǔn)確識(shí)別,接口返回貨幣的名稱、代碼、面值、年份信息;可識(shí)別各類近代常見(jiàn)貨幣,如美元、歐元、英鎊、法郎、澳大利亞元、俄羅斯盧布、日元、韓元、泰銖、印尼盧比等。

創(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)文章

最新評(píng)論