public static void GeneralWithLocatin() { var client = new Baidu.Aip.Ocr.Ocr("Api Key", "Secret Key"); var image = File.ReadAllBytes("图片文件路径"); // 带位置版本 var result = client.GeneralWithLocatin(image, null); }
public static String GeneralWithLocatin(string imgpath) { var client = new Baidu.Aip.Ocr.Ocr(API_KEY, SECRET_KEY); var image = File.ReadAllBytes(imgpath); // 带位置版本 var result = client.GeneralWithLocatin(image, null); return(result.ToString()); }
public static object GeneralBasic(String img_path) { api_key = ConfigurationManager.AppSettings["Api_key"]; secrest_key = ConfigurationManager.AppSettings["Secret_Key"]; var client = new Baidu.Aip.Ocr.Ocr(api_key, secrest_key); var image = File.ReadAllBytes(img_path); // 通用文字识别 var result = client.GeneralWithLocatin(image, null); return(result); }
public static Image GeneralBasic(Image imageIn) { bool isBegin = false; location fwloc = new ImageRotate.location(); location dyczloc = new ImageRotate.location(); var client = new Baidu.Aip.Ocr.Ocr(apiKey, secretKey); var image = ImageToByteArray(imageIn); JObject result = client.GeneralWithLocatin(image, null); JToken js = result["words_result"]; for (int i = 0; i < js.Count(); i++) { JToken item = js[i]; if (item["words"].ToString().Contains("发文时间")) { fwloc.X = int.Parse(item["location"]["left"].ToString()); fwloc.Y = int.Parse(item["location"]["top"].ToString()); fwloc.H = int.Parse(item["location"]["height"].ToString()); fwloc.W = int.Parse(item["location"]["width"].ToString()); } else if (item["words"].ToString().Contains("本打印操作")) { dyczloc.X = int.Parse(item["location"]["left"].ToString()); dyczloc.Y = int.Parse(item["location"]["top"].ToString()); dyczloc.H = int.Parse(item["location"]["height"].ToString()); dyczloc.W = int.Parse(item["location"]["width"].ToString()); } } Bitmap bitmap = new Bitmap(imageIn.Width - 40, dyczloc.Y - fwloc.Y - fwloc.H - 40); Graphics graphic = Graphics.FromImage(bitmap); //截取原图相应区域写入作图区 graphic.DrawImage(imageIn, 0, 0, new Rectangle(20, fwloc.Y + 20 + fwloc.H, imageIn.Width - 40, dyczloc.Y - fwloc.Y - fwloc.H - 60), GraphicsUnit.Pixel); //从作图区生成新图 Image saveImage = Image.FromHbitmap(bitmap.GetHbitmap()); return(saveImage); //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; // } //} return(null); }