Libraryless. Click here for Pure Java version (4402L/29K/99K).
1 | !752 |
2 | |
3 | please include function img_upperWidthToLowerWidth. |
4 | please include function img_averageWidthDividedByHeight. |
5 | please include function img_centralPixelSet. |
6 | please include function img_leftishness. |
7 | |
8 | sS font = "#1004569"; |
9 | static float size = 40f; |
10 | |
11 | static BWImage render(S text) { |
12 | ret autoCroppedBWImage(renderText(font, size, text)); |
13 | } |
14 | |
15 | p { |
16 | BWImage zero = autoCroppedBWImage(renderText(font, size, "0")); |
17 | BWImage one = autoCroppedBWImage(renderText(font, size, "1")); |
18 | showBWImage(zero); |
19 | showBWImage(one); |
20 | Map<S, L<Range>> ranges = new TreeMap; |
21 | |
22 | for (size = 10f; size <= 60f; size++) |
23 | analyze(ll(render("0"), render("1")), ranges, "upperWidthToLowerWidth averageWidthDividedByHeight centralPixelSet leftishness"); |
24 | |
25 | //printStruct(ranges); |
26 | |
27 | for (S key : keys(ranges)) { |
28 | L<Range> l = ranges.get(key); |
29 | if (rangesOverlap(l)) |
30 | print("bad: " + key); |
31 | else |
32 | print("good! " + key); |
33 | } |
34 | } |
35 | |
36 | svoid analyze(L<BWImage> images, Map<S, L<Range>> ranges, S functions) { |
37 | for (S f : splitAtSpace(functions)) { |
38 | L<Range> l = ranges.get(f); |
39 | if (l == null) |
40 | ranges.put(f, l = new L); |
41 | for i over images: { |
42 | BWImage img = images.get(i); |
43 | float val = 0f; |
44 | try { |
45 | val = toFloat(call(mc(), "img_" + f, img)); |
46 | } catch e { printShortException(e); } |
47 | listSet(l, i, addToRange(get(l, i), val), null); |
48 | } |
49 | } |
50 | } |
51 | |
52 | // can overwrite original object |
53 | static Range addToRange(Range r, float val) { |
54 | if (r == null) |
55 | ret new Range(val); |
56 | if (r.min > r.max) |
57 | r.min = r.max = val; |
58 | else { |
59 | if (val < r.min) r.min = val; |
60 | if (val > r.max) r.max = val; |
61 | } |
62 | ret r; |
63 | } |
64 | |
65 | static bool rangesOverlap(Range a, Range b) { |
66 | ret intersectRanges(a, b) != null; |
67 | } |
68 | |
69 | static Range intersectRanges(Range a, Range b) { |
70 | float min = max(a.min, b.min); |
71 | float max = min(a.max, b.max); |
72 | ret min <= max ? new Range(min, max) : null; |
73 | } |
74 | |
75 | static bool rangesOverlap(L<Range> l) { |
76 | assertTrue(l(l) == 2); |
77 | ret rangesOverlap(first(l), last(l)); |
78 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005852 |
Snippet name: | Learn to read [dev.] |
Eternal ID of this version: | #1005852/1 |
Text MD5: | 3b3b55030f527a5ee9d0de0666429f74 |
Transpilation MD5: | 39d1f2e707dd75a300ddca8f33724ae1 |
Author: | stefan |
Category: | javax / ocr |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-12-11 16:52:32 |
Source code size: | 2078 bytes / 78 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 537 / 647 |
Referenced in: | [show references] |