Download Jar. Uses 3874K of libraries. Click here for Pure Java version (15490L/111K).
1 | !7 |
2 | |
3 | static int topTenSize = 1000, maxImages = 1000; |
4 | static MultiSetAndTopTen<S> mstt; // holds md5 |
5 | static SS comments; |
6 | |
7 | p-subst { |
8 | autoRestart(); |
9 | comments = persistentHashMap("Comments"); |
10 | mstt = new MultiSetAndTopTen( |
11 | l_persistentTreeMap("Images + count"), |
12 | l_persistentList("Top Ten")); |
13 | mstt.maxEntries = maxImages; |
14 | mstt.setTopTenSize(topTenSize); |
15 | |
16 | thread "Collect" { |
17 | repeat with sleep 10 { |
18 | deleteUnusedImages(); |
19 | collectIt(); |
20 | } |
21 | } |
22 | |
23 | showButtons( |
24 | "Top " + topTenSize, f showTopTen, |
25 | "Clear", rThread(f clearIt), |
26 | "Current Screen", rThread(f currentScreen)); |
27 | } |
28 | |
29 | svoid collectIt { |
30 | print("Collecting..."); |
31 | lock dbLock(); |
32 | long time = sysNow(); |
33 | BWImage img = shootScreenBW(); |
34 | L<Rect> segments = autoSegment(img); |
35 | for (Rect r : segments) { |
36 | RGBImage clip = img.clip(r).toRGB(); |
37 | S md5 = rgbMD5(clip); |
38 | mstt.add(md5); |
39 | File f = imgFile(md5); |
40 | if (!f.exists()) |
41 | savePNG(f, clip); |
42 | } |
43 | |
44 | print(n(segments, "segment") + " on screen. " + n(mstt.numEntries(), "image") + " in DB. " + n(mstt.numOccurrences(), "occurrence") + ". DB size: " + toM(guessClusteredDirSize(programDir())) + " MB"); |
45 | done2(time); |
46 | } |
47 | |
48 | static File imgFile(S md5) { |
49 | ret screenClipFileForMD5(md5); |
50 | } |
51 | |
52 | svoid showTopTen { |
53 | final L data = map(mstt.topTen(), func(S md5) { |
54 | litorderedmap( |
55 | "Image" := loadBufferedImageOpt(imgFile(md5)), |
56 | "Comment" := unnull(comments.get(md5)), |
57 | "MD5" := md5, "Occurrences" := mstt.get(md5)) |
58 | }); |
59 | |
60 | final JTable table = setRowHeight(40, showTable(data, "Top " + l(data))); |
61 | |
62 | tablePopupMenuItemAndDoubleClick(table, "Comment...", voidfunc(final Int row) { |
63 | fS md5 = getString(data.get(row), "MD5"); |
64 | final JTextField tf = jtextfield(comments.get(md5)); |
65 | showFormTitled("Comment image " + md5, |
66 | //"MD5", md5, |
67 | "Image", new ImageChooser(loadBufferedImage(imgFile(md5))), |
68 | "Comment", tf, |
69 | r { |
70 | S text = getTextTrim(tf); |
71 | comments.put(md5, nullIfEmpty(text)); |
72 | ((DefaultTableModel) table.getModel()).setValueAt(text, row, 1); |
73 | }); |
74 | }); |
75 | } |
76 | |
77 | // Keep all images commented on & all in top 1000 |
78 | svoid deleteUnusedImages { |
79 | Set set = ciSet(); |
80 | set.addAll(mstt.entries()); |
81 | set.addAll(keys(comments)); |
82 | |
83 | for (File f : filesEndingWith(screenClipsDir(), ".png")) |
84 | if (!set.contains(toLower(dropSuffix(".png", f.getName())))) { |
85 | print("Deleting " + f); |
86 | f.delete(); |
87 | } |
88 | } |
89 | |
90 | svoid clearIt { |
91 | lock dbLock(); |
92 | mstt.clear(); |
93 | } |
94 | |
95 | svoid currentScreen { |
96 | clearIt(); |
97 | collectIt(); |
98 | showTopTen(); |
99 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1010705 |
Snippet name: | Teach things on screen [don't use, doesn't use new comments system, also collects every 10] |
Eternal ID of this version: | #1010705/52 |
Text MD5: | ed6987e5631bbf8d9df2b3655e34558e |
Transpilation MD5: | bd588a8dec705687b1682b3dcf9d5207 |
Author: | stefan |
Category: | javax / ocr |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-05-10 17:43:14 |
Source code size: | 2658 bytes / 99 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 542 / 2353 |
Version history: | 51 change(s) |
Referenced in: | [show references] |