sclass ChessPieceRecognizer { MultiMap profiles; double magicCombineFactor = 0.0012589254117941495; int version = 1; void load { long time = sysNow(); profiles = agiBlue_chessPieceProfiles(agiBlue_chessPieceImages_loadedMultiMap(), +version); done2("Loading " + n2(l(profiles), "piece profile"), time); } Pair recognize(BufferedImage img) { ChessPieceProfile1 profile = chessOCR_pieceProfileFromRawImage_1(img); new Lowest lowest; for (unpair S piece, ChessPieceProfile1 p : multiMapToPairs(profiles)) { float sideProfileDiff = floatRatio(byteArraysTotalDiff(profile.sideProfile, p.sideProfile), l(p.sideProfile)); float fillGradeDiff = abs(profile.fillGrade-p.fillGrade); double score = magicCombine(sideProfileDiff, fillGradeDiff); lowest.put(piece, score); } ret pairMapB(d -> errorToPercent(d), lowest.pair()); } // for humans double errorToPercent(double d) { ret 100-d; } double magicCombine(double sideProfileScore, double fillGradeScore) { double sum = sideProfileScore+fillGradeScore/magicCombineFactor; //print("magicCombine " + sideProfileScore + "*" + magicCombineFactor + "+" + fillGradeScore + " = " + sum); ret sum; } toString { ret shortClassName(this) + "(v" + version + ", " + nProfiles(l(profiles)) + ")"; } }