In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Many novices are not very clear about how to connect Unity to Baidu AI to achieve general object and scene recognition. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
API description:
More than 100000 common objects and scenes can be identified. The API returns the names of large categories and subcategories, and supports obtaining the encyclopedia information corresponding to the recognition results. You can also use EasyDL to customize the training platform and custom identification label. It is widely used in business scenes such as image or video content analysis, photo recognition and so on.
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 general object and scene recognition API:
Define the data structure:
Using System; / General object and scene recognition / / [Serializable] public class AdvancedGeneralRecognition {/ 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 / / return result array / public AdvancedGeneralRecognitionResult [] result;} / General object and scene recognition results / [Serializable] public class AdvancedGeneralRecognitionResult {/ / public string keyword; / confidence of the object or scene name in the picture, 0-1 / public float score / the upper tag of the identification result, some tag tags such as coins, animation, tobacco and alcohol, etc. / / public string root; / 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 = "" / General object and scene recognition / Bytes of picture data / the number of results returned from encyclopedia information. / public static AdvancedGeneralRecognition AdvancedGeneral (byte [] bytes, int baikeNum = 0) {var client = new Baidu.Aip.ImageClassify.ImageClassify (apiKey, secretKey) is not returned by default. Try {var options = new Dictionary {{"baike_num", baikeNum},}; var response = client.AdvancedGeneral (bytes, options); AdvancedGeneralRecognition recognition = JsonConvert.DeserializeObject (response.ToString ()); return recognition } catch (Exception error) {Debug.LogError (error);} return null;}}
Test picture:
Using System.IO;using UnityEngine; public class Example: MonoBehaviour {private void Start () {ImageRecognition.AdvancedGeneral (File.ReadAllBytes (Application.dataPath + "/ Picture.jpg"), 1);}}
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.