public static void FormGetResult()
        {
            var form    = new Baidu.Aip.Ocr.Form("Api Key", "Secret Key");
            var options = new Dictionary <string, object>()
            {
                { "result_type", "json" }  // 或者为excel
            };
            var result = form.GetRecognitionResult("123344", options);

            Console.Write(result);
        }
Esempio n. 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;
                }
            }
        }