/// <summary> /// 体温单 /// </summary> /// <param name="path"><图片路径/param> /// <returns>数据</returns> public static dynamic TemperatureChart(string path) { dynamic ddata = new System.Dynamic.ExpandoObject(); var image = File.ReadAllBytes(path); JObject jb; try { jb = Identification.IdentifyImage(path, ApiVersion.General); } catch (NoApiTimesException e) { throw e; } int top = Int32.MaxValue; int left = Int32.MaxValue; int height = 70; int width = 230; var(top_A, left_A, height_A, width_A) = (0, 0, 0, 0); var(top_B, left_B, height_B, width_B) = (0, 0, 0, 0); var A = 0; var B = 0; foreach (var jd in jb["words_result"]) { string words = jd["words"].ToString(); if (words.Contains("体重") || words.Contains("Kg")) { A = 1; top_A = Convert.ToInt32(jd["location"]["top"].ToString()); left_A = Convert.ToInt32(jd["location"]["left"].ToString()); height_A = Convert.ToInt32(jd["location"]["height"].ToString()); width_A = Convert.ToInt32(jd["location"]["width"].ToString()); } if (words.Contains("身高") || words.Contains("cm")) { B = 1; top_B = Convert.ToInt32(jd["location"]["top"].ToString()); left_B = Convert.ToInt32(jd["location"]["left"].ToString()); height_B = Convert.ToInt32(jd["location"]["height"].ToString()); width_B = Convert.ToInt32(jd["location"]["width"].ToString()); } } if (A == 0 && B == 1) { top = top_B - (int)(height_B * 1.2); left = left_B; height = height_B + (int)(height_B * 1.2); width = (int)(width_B * 3.2); } else if (A == 1 && B == 0) { top = top_A; left = left_A; height = height_A + (int)(height_A * 1.2); width = (int)(width_A * 3.2); } else if (A == 1 && B == 1) { top = top_A; left = Math.Min(left_A, left_B); height = height_A + (int)(height_B * 1.2); width = (int)(Math.Max(width_A, width_B) * 3.2); } else { throw new NoFindContextException("找不到\"体重Kg\"和\"身高cm\""); } Bitmap b = new Bitmap(path); var newB = Identification.CutAndPasteBytes(image, width, height, top - 7, left); #if DEBUG DEBUG_saveImage(newB); #endif JObject newJb; try { newJb = Identification.IdentifyImage(newB, ApiVersion.AccurateBasic); } catch (NoApiTimesException e) { throw e; } int tag_Kg_cm_none = 3; foreach (var jd in newJb["words_result"]) { string words = jd["words"].ToString(); if (new Regex(@"^[0-9]*$").IsMatch(words)) { if (tag_Kg_cm_none == 3) { ddata.Width = Convert.ToDouble(words); tag_Kg_cm_none = 2; } else if (tag_Kg_cm_none == 2) { ddata.Height = Convert.ToDouble(words); tag_Kg_cm_none = 1; } else if (tag_Kg_cm_none == 1) { break; } } } return(ddata); }
public override void CutPicture(ResetPictures reset) { var image = reset.originImages[0]; JObject jb; try { jb = Identification.IdentifyImage(image, ApiVersion.General); } catch (NoApiTimesException e) { throw e; } int top = Int32.MaxValue; int left = Int32.MaxValue; int height = 70; int width = 230; var(top_A, left_A, height_A, width_A) = (0, 0, 0, 0); var(top_B, left_B, height_B, width_B) = (0, 0, 0, 0); var A = 0; var B = 0; foreach (var jd in jb["words_result"]) { string words = jd["words"].ToString(); if (words.Contains("体重") || words.Contains("Kg")) { A = 1; top_A = Convert.ToInt32(jd["location"]["top"].ToString()); left_A = Convert.ToInt32(jd["location"]["left"].ToString()); height_A = Convert.ToInt32(jd["location"]["height"].ToString()); width_A = Convert.ToInt32(jd["location"]["width"].ToString()); } if (words.Contains("身高") || words.Contains("cm")) { B = 1; top_B = Convert.ToInt32(jd["location"]["top"].ToString()); left_B = Convert.ToInt32(jd["location"]["left"].ToString()); height_B = Convert.ToInt32(jd["location"]["height"].ToString()); width_B = Convert.ToInt32(jd["location"]["width"].ToString()); } } if (A == 0 && B == 1) { top = top_B - (int)(height_B * 1.2); left = left_B; height = height_B + (int)(height_B * 1.2); width = (int)(width_B * 3.2); } else if (A == 1 && B == 0) { top = top_A; left = left_A; height = height_A + (int)(height_A * 1.2); width = (int)(width_A * 3.2); } else if (A == 1 && B == 1) { top = top_A; left = Math.Min(left_A, left_B); height = height_A + (int)(height_B * 1.2); width = (int)(Math.Max(width_A, width_B) * 3.2); } else { throw new NoFindContextException("找不到\"体重Kg\"和\"身高cm\""); } reset.rearrayImages.Add(Identification.CutAndPasteBytes(image, width, height, top - 7, left)); //base.CutPicture(reset); }