• C# 印刷文字识别-营业执照


       private const String host = "https://dm-58.data.aliyun.com";
            private const String path = "/rest/160601/ocr/ocr_business_license.json";
            private const String method = "POST";
            private const String appcode = "自己的AppCode";  
            public static void Main(string[] args)
            {
                String querys = "";
                String img_file = "图片路径";       
                FileStream fs = new FileStream(img_file, FileMode.Open);
                BinaryReader br = new BinaryReader(fs);
                byte[] contentBytes = br.ReadBytes(Convert.ToInt32(fs.Length));
                String base64 = System.Convert.ToBase64String(contentBytes);
                String bodys = "{"image":"" + base64 + """;  //对图片内容进行Base64编码
    
    
                String url = host + path;
                HttpWebRequest httpRequest = null;
                HttpWebResponse httpResponse = null;
    
                if (0 < querys.Length)
                {
                    url = url + "?" + querys;
                }
    
                if (host.Contains("https://"))
                {
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                    httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
                }
                else
                {
                    httpRequest = (HttpWebRequest)WebRequest.Create(url);
                }
                httpRequest.Method = method;
                httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
                //根据API的要求,定义相对应的Content-Type
                httpRequest.ContentType = "application/json; charset=UTF-8";
                // 设置并解析  格式
                String config = "{\"side\":\"face\"}";
                bodys = "{"image":"" + base64 + """;
                if (config.Length > 0)
                {
                    bodys += ","configure" :"" + config + """;
                }
                bodys += "}";
    
    
                if (0 < bodys.Length)
                {
                    byte[] data = Encoding.UTF8.GetBytes(bodys);
                    using (Stream stream = httpRequest.GetRequestStream())
                    {
                        stream.Write(data, 0, data.Length);
                    }
                }
                try
                {
                    httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                }
                catch (WebException ex)
                {
                    httpResponse = (HttpWebResponse)ex.Response;
                }
    
                Console.WriteLine(httpResponse.StatusCode);
                Console.WriteLine(httpResponse.Method);
                Console.WriteLine(httpResponse.Headers);
                Stream st = httpResponse.GetResponseStream();
                StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
                Console.WriteLine(reader.ReadToEnd());
                Console.WriteLine("
    ");
                Console.ReadLine();
    
            }
            public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
            {
                return true;
            }
    

      

  • 相关阅读:
    poj 2109Power of Cryptography
    poj 2632Crashing Robots
    poj 2586Y2K Accounting Bug
    linux0.12中文件系统的一些理解
    latex初学者的经验
    关于linux0.12中的add_entry中bread中的些猜测
    uid gid euid egid详解
    关于linux0.12文件系统目录大小的一个发现
    我的初级muttrc配置
    使用STM32的USB模块中后对USB缓冲区的认识
  • 原文地址:https://www.cnblogs.com/BabyRui/p/10731357.html
Copyright © 2020-2023  润新知