예제 #1
0
        public static string BaiduBasic(string filePath, Image img = null)
        {
            if (AccessToken == "")
            {
                return("错误:请检查接口设置!");
            }

            string base64    = "";
            string returnStr = "";
            string url       = Accurate ? "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=" + AccessToken :
                               "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=" + AccessToken;

            if (img == null)
            {
                base64 = Base64Helper.getFileBase64(filePath); // 图片文件的 base64 编码
            }
            else
            {
                base64 = Base64Helper.getFileBase64("", Base64Helper.ImgToBytes(img)); // 剪切板图片的 base64 编码
            }

            string data   = "image=" + HttpUtility.UrlEncode(base64);
            string result = HttpClient.Post(data, url);
            var    jArray = JArray.Parse(((JObject)JsonConvert.DeserializeObject(result))["words_result"].ToString());

            returnStr = checked_txt(jArray, 1, "words");

            return(returnStr);
        }
예제 #2
0
        public static string BaiduBasic(string filePath, Image img = null)
        {
            if (AccessToken == "")
            {
                return("错误:请检查接口设置!");
            }
            string url = Accurate ? "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=" + AccessToken :
                         "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=" + AccessToken;
            string base64 = img == null?Base64Helper.getFileBase64(filePath) : Base64Helper.getFileBase64("", Base64Helper.ImgToBytes(img));

            string data   = "image=" + HttpUtility.UrlEncode(base64) + "&language_type=" + Language;
            string result = HttpClient.Post(data, url);
            string returnStr;

            if (result.Contains("error_msg"))
            {
                split_txt   = result;
                typeset_txt = result;
                returnStr   = result;
            }
            else
            {
                var jArray = JArray.Parse(((JObject)JsonConvert.DeserializeObject(result))["words_result"].ToString());
                returnStr = checked_txt(jArray, 1, "words");
            }
            return(returnStr);
        }
예제 #3
0
        public static string OCROffile(string filePath, Image img = null)
        {
            string base64 = img == null?Base64Helper.getFileBase64(filePath) : Base64Helper.getFileBase64("", Base64Helper.ImgToBytes(img));

            string returnStr = PaddleOCRText(base64);

            returnStr = Encoding.UTF8.GetString(Encoding.Default.GetBytes(returnStr));
            return(returnStr);
        }
예제 #4
0
        // 表格文字识别(异步接口)
        public static string BaiduForm(string filePath, Image img = null)
        {
            if (AccessToken == "")
            {
                return("错误:请检查接口设置!");
            }
            string url    = "https://aip.baidubce.com/rest/2.0/solution/v1/form_ocr/request?access_token=" + AccessToken;
            string base64 = img == null?Base64Helper.getFileBase64(filePath) : Base64Helper.getFileBase64("", Base64Helper.ImgToBytes(img));

            string data      = "image=" + HttpUtility.UrlEncode(base64) + "&is_sync=true&request_type=excel";
            string result    = HttpClient.Post(data, url);
            string returnStr = ((JObject)JsonConvert.DeserializeObject(result))["result"]["result_data"].ToString();

            return(returnStr);
        }