Пример #1
0
        /// <summary>
        /// 获取Access Token
        /// </summary>
        /// <returns></returns>
        public static string?GetAccessToken(this BaiduSetting setting)
        {
            string  url    = $"https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={setting.client_id}&client_secret={setting.client_secret}";
            string  result = NetAgent.UploadData(url, string.Empty, Encoding.UTF8);
            JObject info   = JObject.Parse(result);

            return(info["access_token"]?.Value <string>());
        }
Пример #2
0
        /// <summary>
        /// 通用文字识别(标准含位置版)
        /// 0.01/次  10QPS
        /// </summary>
        /// <returns></returns>
        public static List <OCRGeneralResult>?general(this BaiduSetting setting, Bitmap bitmap)
        {
            string? access_token         = setting.GetAccessToken();
            string  url                  = $"https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token={access_token}";
            string  image                = System.Web.HttpUtility.UrlEncode(bitmap.ToBase64());
            string  result               = NetAgent.UploadData(url, $"image={image}", Encoding.UTF8);
            JObject info                 = JObject.Parse(result);
            List <OCRGeneralResult> list = new();

            foreach (JObject item in info["words_result"]?.Value <JArray>() ?? new JArray())
            {
                list.Add(new OCRGeneralResult(item));
            }
            return(list);
        }