/// <summary> /// 根据样本识别并计算结果 /// </summary> /// <param name="pics"></param> public int Calculate(Bitmap[] pics) { int total = 0; try { List <code> codes = new List <code>(); LevenshteinDistance ld = new LevenshteinDistance(); string result = string.Empty; int a = 0; int b = 0; string option = string.Empty; codes.Clear(); using (StreamReader sr = new StreamReader(path + @"\DigitalDotMatrix.ini")) { while (!sr.EndOfStream) { string[] temp = sr.ReadLine().Split(':'); code c = new code(); c.Key = temp[1]; c.Value = temp[0]; codes.Add(c); } } for (int i = 0; i < 3; i++) { string code = vfc.GetSingleBmpCode(pics[i], 128);//得到代码串 decimal max = 0.0M; string value = ""; for (int m = 0; m < codes.Count; m++) { code c = codes[m]; decimal parent = ld.LevenshteinDistancePercent(code, c.Key); if (parent > max) { max = parent; value = c.Value; } } if (IsNumeric(value) && i == 0) { a = int.Parse(value); } else if (IsNumeric(value) && i == 2) { b = int.Parse(value); } else { option = value; } result = result + value; } switch (option) { case "-": { total = a - b; break; } case "+": { total = a + b; break; } default: break; } } catch (Exception ex) { WriteLog(ex.ToString()); } return(total); }