最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2022年02月10日 17:16:10   作者:CoderZ1010  
本文將介紹如何利用Unity接入百度AI從而實(shí)現(xiàn)果蔬識(shí)別,可以做到識(shí)別近千種水果和蔬菜的名稱,可自定義返回識(shí)別結(jié)果數(shù)。感興趣的小伙伴可以了解一下

接口介紹:

識(shí)別近千種水果和蔬菜的名稱,適用于識(shí)別只含有一種果蔬的圖片,可自定義返回識(shí)別結(jié)果數(shù),適用于果蔬介紹相關(guān)的美食類APP中。

創(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 IngredientRecognition
{
    /// <summary>
    /// 唯一的log id,用于問(wèn)題定位
    /// </summary>
    public float log_id;
    /// <summary>
    /// 返回結(jié)果數(shù)目,及result數(shù)組中的元素個(gè)數(shù)
    /// </summary>
    public int result_num;
    /// <summary>
    /// 識(shí)別結(jié)果數(shù)組
    /// </summary>
    public IngredientRecognitionResult[] result;
}
 
/// <summary>
/// 果蔬識(shí)別結(jié)果
/// </summary>
[Serializable]
public class IngredientRecognitionResult
{
    /// <summary>
    /// 食材名稱
    /// </summary>
    public string name;
    /// <summary>
    /// 置信度
    /// </summary>
    public float score;
}

下載C# SDK:

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

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

在下載的SDK中并未發(fā)現(xiàn)通過(guò)url調(diào)用的重載函數(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>
    /// <param name="topNum">返回預(yù)測(cè)得分top結(jié)果數(shù),如果為空或小于等于0默認(rèn)為5;如果大于20默認(rèn)20</param>
    /// <returns></returns>
    public static IngredientRecognition Ingredient(byte[] bytes, int topNum = 5)
    {
        var client = new Baidu.Aip.ImageClassify.ImageClassify(apiKey, secretKey);
        try
        {
            var options = new Dictionary<string, object>
            {
                { "top_num", topNum },
            };
            var response = client.Ingredient(bytes, options);
            IngredientRecognition ingredientRecognition = JsonConvert.DeserializeObject<IngredientRecognition>(response.ToString());
            return ingredientRecognition;
        }
        catch (Exception error)
        {
            Debug.LogError(error);
        }
        return null;
    }
}

測(cè)試圖片:

using System.IO;
using UnityEngine;
 
public class Example : MonoBehaviour
{
    private void Start()
    {
        ImageRecognition.Ingredient(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)論

天长市| 陇川县| 阿拉善盟| 临沭县| 凯里市| 平阳县| 建始县| 东光县| 永年县| 乌什县| 金阳县| 齐齐哈尔市| 平湖市| 贡嘎县| 岳阳市| 武平县| 富川| 方正县| 平谷区| 林芝县| 庆安县| 东乡县| 电白县| 泉州市| 凤山县| 池州市| 于都县| 宜昌市| 安陆市| 桑日县| 永平县| 宁国市| 哈尔滨市| 丹东市| 互助| 克什克腾旗| 吉林市| 肃南| 始兴县| 万荣县| 内乡县|