最新国产好看的视频,伊人天堂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,用于問題定位
    /// </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)庫導(dǎo)入到Unity中:

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

在下載的SDK中并未發(fā)現(xiàn)通過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)論

互助| 会昌县| 高要市| 余江县| 宁夏| 正安县| 定西市| 开化县| 紫金县| 绥宁县| 井冈山市| 华池县| 郧西县| 都昌县| 丰镇市| 柯坪县| 当阳市| 濉溪县| 宿松县| 丰原市| 红原县| 云安县| 安图县| 始兴县| 阜平县| 来凤县| 香格里拉县| 衡水市| 抚州市| 洛隆县| 塔河县| 乐业县| 安多县| 共和县| 赣榆县| 新田县| 若尔盖县| 云林县| 石河子市| 达日县| 固原市|