Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

85
LINES

< > BotCompany Repo | #1004654 // Algorithm Sucker - Recognizing "Ticketing" (works)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (3093L/19K/65K).

!752

static new Highest<S> highest;

sclass Infos {
  Map<BWImage, S> chars;
  bool debug;
}

static interface Algorithm {
  S recognizeWord(BWImage img, Infos infos);
}

static Infos infos;
static Map<BWImage, S> words;

p {
  load("highest");
}

please include function charRangeToChar.

// returns true when happy with the sucking package
static bool suck(S desc, Algorithm algorithm) {
  print("Best score: " + highest.score);
  if (highest.update(desc, scoreAlgorithm(algorithm))) {
    save("highest");
    true;
  }
  false;
}

static synchronized double scoreAlgorithm(Algorithm algorithm) {
  if (infos == null) {
    infos = new Infos;
    infos.chars = mapValues("charRangeToChar", loadGlyphSheet("#1004645"));
  }
  
  if (words == null)
    words = loadGlyphSheet("#1004649");
  
  printStructure(values(words));
  
  double score = 0, total = 0;
  for (BWImage img : keys(words)) {
    infos.debug = false;
    S w;
    try {
      w = algorithm.recognizeWord(img, infos);
    } catch e {
      w = exceptionToStringShort(e);
      silentException(e);
    }
    S real = words.get(img);
    print(real + " => " + w);
    ++total;
    if (eq(real, w)) {
      ++score;
      print("  ok!");
    } else {
      print("  oops...");
      if (l(real) != 0) {
        int lev = leven(real, w);
        double s = max(0, 1-lev/(double) l(real));
        print("score: " + s + " (lev: " + lev + ")");
        score += s;
      }

      // Do it again for debug output (could be skipped if needed)
      
      infos.debug = true;
      try {
        algorithm.recognizeWord(img, infos);
      } catch {}
    }
  }
  
  print();
  print("SCORE: " + formatDouble(score, 1) + "/" + formatDouble(total, 1));
  
  if (lastSilentException() != null)
    printStackTrace(lastSilentException());

  ret score*100/total;
}

Author comment

Began life as a copy of #1004646

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004654
Snippet name: Algorithm Sucker - Recognizing "Ticketing" (works)
Eternal ID of this version: #1004654/1
Text MD5: 92b2cd8557a2db52ff3ba209a7bda9a8
Transpilation MD5: edcf699aa979d7f5f3711744757fe10d
Author: stefan
Category: javax / images
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-26 00:21:50
Source code size: 1907 bytes / 85 lines
Pitched / IR pitched: No / No
Views / Downloads: 531 / 861
Referenced in: [show references]