介面介紹:
識別影像中的貨幣型別,以紙幣為主,正反面均可準確識別,介面回傳貨幣的名稱、代碼、面值、年份資訊;可識別各類近代常見貨幣,如美元、歐元、英鎊、法郎、澳大利亞元、俄羅斯盧布、日元、韓元、泰銖、印尼盧比等,
創建應用:
在產品服務中搜索影像識別,創建應用,獲取AppID、APIKey、SecretKey資訊:


查閱官方檔案,以下是貨幣識別介面回傳資料引數詳情:

定義資料結構:
using System;
/// <summary>
/// 貨幣識別
/// </summary>
[Serializable]
public class CurrencyRecognition
{
/// <summary>
/// 請求標識碼,亂數,唯一
/// </summary>
public int log_id;
/// <summary>
/// 識別結果
/// </summary>
public CurrencyRecognitionResult result;
}
/// <summary>
/// 貨幣識別結果
/// </summary>
[Serializable]
public class CurrencyRecognitionResult
{
/// <summary>
/// 判斷是否回傳詳細資訊(除貨幣名稱之外的其他欄位),含有回傳1,不含有回傳0
/// </summary>
public int hasdetail;
/// <summary>
/// 貨幣名稱,無法識別回傳空
/// </summary>
public string currencyName;
/// <summary>
/// 貨幣代碼,hasdetail = 0時,表示無法識別,該欄位不回傳
/// </summary>
public string currencyCode;
/// <summary>
/// 貨幣面值,hasdetail = 0時,表示無法識別,該欄位不回傳
/// </summary>
public string currencyDenomination;
/// <summary>
/// 貨幣年份,hasdetail = 0時,表示無法識別,該欄位不回傳
/// </summary>
public string year;
}
下載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 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>
/// 貨幣識別
/// </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;
}
}
測驗圖片:

using System.IO;
using UnityEngine;
public class Example : MonoBehaviour
{
private void Start()
{
ImageRecognition.Currency(File.ReadAllBytes(Application.dataPath + "/Picture.jpg"));
}
}

歡迎關注公眾號 “當代野生程式猿”

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/401479.html
標籤:其他
