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).

1  
!752
2  
3  
static new Highest<S> highest;
4  
5  
sclass Infos {
6  
  Map<BWImage, S> chars;
7  
  bool debug;
8  
}
9  
10  
static interface Algorithm {
11  
  S recognizeWord(BWImage img, Infos infos);
12  
}
13  
14  
static Infos infos;
15  
static Map<BWImage, S> words;
16  
17  
p {
18  
  load("highest");
19  
}
20  
21  
please include function charRangeToChar.
22  
23  
// returns true when happy with the sucking package
24  
static bool suck(S desc, Algorithm algorithm) {
25  
  print("Best score: " + highest.score);
26  
  if (highest.update(desc, scoreAlgorithm(algorithm))) {
27  
    save("highest");
28  
    true;
29  
  }
30  
  false;
31  
}
32  
33  
static synchronized double scoreAlgorithm(Algorithm algorithm) {
34  
  if (infos == null) {
35  
    infos = new Infos;
36  
    infos.chars = mapValues("charRangeToChar", loadGlyphSheet("#1004645"));
37  
  }
38  
  
39  
  if (words == null)
40  
    words = loadGlyphSheet("#1004649");
41  
  
42  
  printStructure(values(words));
43  
  
44  
  double score = 0, total = 0;
45  
  for (BWImage img : keys(words)) {
46  
    infos.debug = false;
47  
    S w;
48  
    try {
49  
      w = algorithm.recognizeWord(img, infos);
50  
    } catch e {
51  
      w = exceptionToStringShort(e);
52  
      silentException(e);
53  
    }
54  
    S real = words.get(img);
55  
    print(real + " => " + w);
56  
    ++total;
57  
    if (eq(real, w)) {
58  
      ++score;
59  
      print("  ok!");
60  
    } else {
61  
      print("  oops...");
62  
      if (l(real) != 0) {
63  
        int lev = leven(real, w);
64  
        double s = max(0, 1-lev/(double) l(real));
65  
        print("score: " + s + " (lev: " + lev + ")");
66  
        score += s;
67  
      }
68  
69  
      // Do it again for debug output (could be skipped if needed)
70  
      
71  
      infos.debug = true;
72  
      try {
73  
        algorithm.recognizeWord(img, infos);
74  
      } catch {}
75  
    }
76  
  }
77  
  
78  
  print();
79  
  print("SCORE: " + formatDouble(score, 1) + "/" + formatDouble(total, 1));
80  
  
81  
  if (lastSilentException() != null)
82  
    printStackTrace(lastSilentException());
83  
84  
  ret score*100/total;
85  
}

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: 592 / 946
Referenced in: [show references]