In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to use Unity code to identify dishes". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
API description:
Identify more than 9,000 kinds of dishes, support customers to create their own food library, accurately identify the name, location and calorie information of dishes in the picture, and obtain encyclopedia information, which is suitable for a variety of business scenarios where customers identify dishes.
Create an application:
Search for image recognition in product services, create applications, and obtain AppID, APIKey, SecretKey information:
Check the official documents. The following is the details of the data parameters returned by the dish identification API:
Define the data structure:
Using System; / dish identification / / [Serializable] public class DishRecognition {/ unique log id for problem location / public float log_id; / the number of results returned, and the number of elements in the result array / public int result_num / public DishRecognitionResult [] result;} / [Serializable] public class DishRecognitionResult {/ public string name; / calories per 100g of calorie content / public float calorie per 100g of calorie content / the confidence value of each line in the recognition result, 0-1 / public float probability; / encyclopedia entry / public BaikeInfo baike_info;} [Serializable] public class BaikeInfo {/ corresponding to the Baidu encyclopedia page link / public string baike_url / Encyclopedia picture link / public string image_url; / Encyclopedia content description / public string description;} corresponding to the recognition result
Download C# SDK:
Import the AipSdk.dll dynamic library into Unity when the download is complete:
The following are the details of the parameters passed when the API is called:
Encapsulate the calling function:
Using System;using System.Collections.Generic;using UnityEngine; / Image recognition / public class ImageRecognition {/ / the following information is available on the Baidu developer Center console to create an application and get private const string appID = ""; private const string apiKey = ""; private const string secretKey = "" / the byte data of the picture / returns the number of predicted score top results. The default is 5 / the default is 0.95.This parameter can be used to adjust the recognition effect and reduce the non-vegetable recognition rate. / returns the number of results of encyclopedia information. / public static DishRecognition Dish is not returned by default (byte [] bytes, int topNum = 5, float filterThreshold = 0.95f, int baikeNum = 0) {var client = new Baidu.Aip.ImageClassify.ImageClassify (apiKey, secretKey) Try {var options = new Dictionary {{"top_num", topNum}, {"filter_threshold", Mathf.Clamp01 (filterThreshold)}, {"baike_num", baikeNum}}; var response = client.DishDetect (bytes, options) DishRecognition dishRecognition = JsonConvert.DeserializeObject (response.ToString ()); return dishRecognition;} catch (Exception error) {Debug.LogError (error);} return null;}}
Test picture:
Using System.IO;using UnityEngine; public class Example: MonoBehaviour {private void Start () {ImageRecognition.Dish (File.ReadAllBytes (Application.dataPath + "/ Picture.jpg");}}
This is the end of the content of "how to use Unity code to identify dishes". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.