In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about Unity how to achieve OCR character recognition function, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
First, log in to Baidu developer Center and search for character recognition services:
Create an application to obtain the key information of AppID, APIKey and SecretKey:
Download C # SDK and import the AipSdk.dll dynamic library into Unity:
This article takes general character recognition as an example, referring to the official documents, the following is the return data structure of general character recognition:
Define the corresponding data structure in Unity:
Using System; / General character recognition / [Serializable] public class GeneralOcr {/ Image Direction-1 undefined 0 sine 1 counterclockwise 90 degrees 2 counterclockwise 180 degrees 3 counterclockwise 270 degrees / public int direction; / unique log id for problem location / public int log_id / / number of identification results, indicating the number of elements of the words_result / public int words_result_num; / location and recognition result array / public string [] words_result; / line confidence information / public Probability probability } / Line confidence Information / [Serializable] public class Probability {/ Line confidence average / public int average; / Line confidence Variance / public int variance; / minimum Line confidence / public int min;}
Here are the relevant parameters passed in during the call:
Encapsulate the calling function:
Using System;using System.Collections.Generic;using UnityEngine; public class OCR {/ / the following information can be obtained by creating an application in Baidu developer Center and getting private const string appID = ""; private const string apiKey = ""; private const string secretKey = "" / Universal text recognition / Picture byte data / recognition language type default CHN_ENG Chinese and English mixed / whether to detect the orientation of the image / whether to detect the language Currently, Chinese, English, Japanese and Korean / whether to return the confidence of each line in the recognition result / public static GeneralOcr General (byte [] bytes, string language = "CHN_ENG", bool detectDirection = false, bool detectLanguage = false, bool probability = false) {var client = new Baidu.Aip.Ocr.Ocr (apiKey, secretKey) Try {var options = new Dictionary {{"language_type", language}, {"detect_direction", detectDirection}, {"detect_language", detectLanguage}, {"probability", probability}}; var response = client.GeneralBasic (bytes, options) GeneralOcr generalOcr = JsonUtility.FromJson (response.ToString ()); return generalOcr;} catch (Exception error) {Debug.LogError (error);} return null;}}
The above is how to call the API with image byte data. You can also call it through URL. You only need to replace GeneralBasic with the overloaded function GeneralBasicUrl:
Test picture:
OCR.General (File.ReadAllBytes (Application.dataPath + "/ Picture.jpg"))
After reading the above, do you have any further understanding of how Unity implements OCR character recognition? If you want to know more knowledge or related content, 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.