Libraryless. Click here for Pure Java version (9242L/64K/215K).
1 | !752 |
2 | |
3 | static BWImage img; |
4 | static ImageSurface is2; |
5 | static float threshold = 0.99f; // for horizontalAutoSplit |
6 | static JTable table; |
7 | static JTextField tfText; |
8 | static L<Rect> split; |
9 | static L<BWImage> characters; |
10 | |
11 | concepts. |
12 | |
13 | concept Result { |
14 | BWImage inputImage; |
15 | float horizontalSplitThreshold; |
16 | L<BWImage> characters; |
17 | //Bool splitOK; |
18 | S text; |
19 | } |
20 | |
21 | p { |
22 | concepts(); |
23 | dbBot(); |
24 | if (img == null) |
25 | img = getBWImageFromClipboard(); |
26 | if (img == null) |
27 | img = loadBWImage("#1005702"); |
28 | update(); |
29 | } |
30 | |
31 | svoid update() { |
32 | RGBImage vis = visualize().toRGB(); |
33 | if (is2 == null) { |
34 | is2 = showZoomedImage(vis); |
35 | addToWindowAndPack(is2, liveSliderZeroToOne(threshold/10000f*9999f, voidfunc(float x) { |
36 | threshold = x*10000f/9999f; |
37 | update(); |
38 | })); |
39 | } else |
40 | is2.setImage(vis); |
41 | |
42 | // show table |
43 | |
44 | new L<L> data; |
45 | characters = new L; |
46 | for (Rect r : split) { |
47 | BWImage clip = img.clip(r); |
48 | characters.add(clip); |
49 | data.add(ll(clip.getBufferedImage(), md5OfBWImage(clip))); |
50 | } |
51 | bool first = table == null; |
52 | table = showTableWithImages("Characters + MD5", splitAtSpace("Character MD5"), data, table); |
53 | if (first) { |
54 | table.setRowHeight(25); |
55 | addToWindow(table, centerAndEast( |
56 | withLabel("Text:", tfText = new JTextField), |
57 | jbutton("Save result", "saveResult"))); |
58 | onEnter(tfText, "saveResult"); |
59 | } |
60 | } |
61 | |
62 | svoid saveResult { |
63 | S text = tfText.getText(); |
64 | /*if (l(text) != l(characters)) |
65 | messageBox("Character count doesn't match! " + l(text) + " vs " + l(characters)); |
66 | else*/ { |
67 | Result result = cnew(Result, |
68 | inputImage := img, horizontalSplitThreshold := threshold, |
69 | +characters, +text); |
70 | messageBox("Result saved! id: " + result.id); |
71 | } |
72 | } |
73 | |
74 | static BWImage visualize() { |
75 | BWImage im = new BWImage(img); |
76 | for (Rect r : split = horizontalAutoSplit(img, threshold)) { |
77 | r = autoCropOfBWImage(img, r); |
78 | darkenBWImagePart(im, r); |
79 | } |
80 | ret im; |
81 | } |
Began life as a copy of #1005711
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005726 |
Snippet name: | Split text into characters with table of characters and MD5s |
Eternal ID of this version: | #1005726/1 |
Text MD5: | 127c68bd71dfc2fcd2a27e256b604f78 |
Transpilation MD5: | 566160e7cde37c0d4ec57af031d98435 |
Author: | stefan |
Category: | javax / ocr |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-12-18 00:18:28 |
Source code size: | 1998 bytes / 81 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 530 / 1122 |
Referenced in: | [show references] |