Warning: session_start(): open(/var/lib/php/sessions/sess_k7fftjpbl83q4ee0oa47vaddfv, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
sclass ChessPieceRecognizer {
MultiMap profiles;
//new Map fillGradeThresholdsByPiece;
double magicCombineFactor = 0.0012589254117941495;
void load {
long time = sysNow();
profiles = agiBlue_chessPieceProfiles();
/*for (S piece : ai_6chessPieces()) {
L w = collect fillGrade(profiles.get("white " + piece));
L b = collect fillGrade(profiles.get("black " + piece));
float white = floatAverage(w);
float black = floatAverage(b);
print("white/black " + piece + " avg: " + white + "/" + black);
print("white/black " + piece + " min/max: " + floatMax(w) + "/" + floatMin(b));
fillGradeThresholdsByPiece.put(piece, avg(white, black));
}*/
//profiles = mapMultiMapKeys lastJavaToken(profiles); // drop color
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;
}
}