public static void FormBegin()
        {
            var form  = new Baidu.Aip.Ocr.Form("Api Key", "Secret Key");
            var image = File.ReadAllBytes("图片文件路径");

            form.DebugLog = false;  // 是否开启调试日志

            var result = form.BeginRecognition(image);

            Console.Write(result);
        }
예제 #2
0
        public static void FormBegin(Image imageIn)
        {
            bool isBegin = false;

            var form = new Baidu.Aip.Ocr.Form(apiKey, secretKey);
            //var client = new Baidu.Aip.Ocr.Ocr(apiKey, secretKey);
            var     image  = ImageToByteArray(imageIn);
            JObject result = form.BeginRecognition(image);
            // JObject result = client.GeneralBasic(image, null);
            var options = new Dictionary <string, object>()
            {
                { "result_type", "json" }  // 或者为excel
            };
            JToken js = result["result"][0]["request_id"];

            JObject result1;

            do
            {
                result1 = form.GetRecognitionResult(js.ToString(), options);
            }while (result1["result"]["ret_code"].ToString() != "3");



            string rid = null, aid = null;
            int    index = 0;

            foreach (var j in js)
            {
                var s = j["words"].ToString();

                if (s.StartsWith("发文时间"))
                {
                    DateTime dt = DateTime.Parse(s.Split(':')[1]);
                }

                if (isBegin)
                {
                    switch (index)
                    {
                    case 0:
                        index++;
                        rid = s;
                        break;

                    case 1:
                        index++;
                        aid = s;
                        break;

                    case 2:

                        index = 0;
                        break;
                    }
                }
                if (s.StartsWith("本打印操作"))
                {
                    isBegin = false;
                }
                if (s == "备注")
                {
                    isBegin = true;
                }
            }
        }