ORC图片识别文字
调用百度的接口,每月有一千次的免费额度,百度的接口文档写得真好啊。。代码全列出来,复制粘贴就好了
using System; using System.IO; using RestSharp;//依赖版本106.15.0 https://www.nuget.org/packages/RestSharp/106.15.0 using Newtonsoft.Json; //https://www.nuget.org/packages/Newtonsoft.Json namespace OrcTest { public class Program { const string API_KEY = "2G6YLMnNfochiBm7APGffY0P"; const string SECRET_KEY = "gElZS22qsMShdHheh2iY48em0WZYgF5j"; public static void Main(string[] args) { var client = new RestClient($"https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token={GetAccessToken()}"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddHeader("Accept", "application/json"); request.AddParameter("url", "http://www.niunan.net/images/orctest.jpg"); request.AddParameter("detect_direction", "false"); request.AddParameter("paragraph", "false"); request.AddParameter("probability", "false"); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); } /** * 使用 AK,SK 生成鉴权签名(Access Token) * @return 鉴权签名信息(Access Token) */ static string GetAccessToken() { var client = new RestClient($"https://aip.baidubce.com/oauth/2.0/token") ; client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddParameter("grant_type", "client_credentials"); request.AddParameter("client_id", API_KEY); request.AddParameter("client_secret", SECRET_KEY); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); var result = JsonConvert.DeserializeObject<dynamic>(response.Content); return result.access_token.ToString(); } } }