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); }
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); }
public static void FormToExcel() { var form = new Baidu.Aip.Ocr.Form("Api Key", "Secret Key"); var image = File.ReadAllBytes("图片文件路径"); form.DebugLog = false; // 是否开启调试日志 // 识别为Excel var result = form.RecognizeToExcel(image); Console.Write(result); }
public static void FormToJson() { var form = new Baidu.Aip.Ocr.Form(AiKeySecret.ApiKey, AiKeySecret.SecretKey); var image = File.ReadAllBytes("图片文件路径"); form.DebugLog = false; // 是否开启调试日志 // 识别为Json var result = form.RecognizeToJson(image); Console.Write(result); }
//调用百度识图API public static void FormToExcel(string picPath) { var form = new Baidu.Aip.Ocr.Form("mQgLfOLfbgjSE7NEY0aoruWD", "8js5uXvSqPdDPrKyod1qsXcE8ISjyxDZ"); var image = File.ReadAllBytes(picPath); form.DebugLog = true; // 是否开启调试日志 // 识别为Excel var result = form.RecognizeToExcel(image); //MessageBox.Show(result); Console.Write(result); }
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; } } }