Uses 3874K of libraries. Click here for Pure Java version (11693L/83K/287K).
1 | !7 |
2 | |
3 | concept Grab { |
4 | new Ref<PNGFile> screenshot; |
5 | Pt point; |
6 | new MultiSet<Rect> sizes; |
7 | } |
8 | |
9 | p-substance-thread { |
10 | shootScreen_useScrot = true; // method without black spots |
11 | db(); |
12 | awt { |
13 | showControls(jCenteredLine( |
14 | jbutton("Grab", "grab"), |
15 | jbutton("Find", rThread("find")))); |
16 | final JTable table = showConceptsTable(Grab); |
17 | addToWindow(table, |
18 | tableDependButton(table, "Show", r { |
19 | visualize(selectedConcept(table, Grab)); |
20 | })); |
21 | } |
22 | } |
23 | |
24 | svoid grab { |
25 | trackOneClick(voidfunc(final Point p) { |
26 | thread { |
27 | sleep(500); // allow screen behind red dot to be repainted |
28 | Grab grab = cnew(Grab, |
29 | screenshot := new PNGFile(shootScreenBufferedImage()), |
30 | point := new Pt(p) |
31 | ); |
32 | infoBox("Grabbed! " + grab.id); |
33 | } |
34 | }); |
35 | } |
36 | |
37 | svoid find { |
38 | float ppt = 0.1f; // per pixel tolerance |
39 | RGBImage imgB = rgbShootScreen(); |
40 | int w = imgB.w(), h = imgB.h(); |
41 | for (Grab grab) { |
42 | print ("Searching " + grab.id + "..."); |
43 | RGBImage imgA = new RGBImage(grab.screenshot->getImage()); |
44 | Pt p = grab.point; |
45 | int col = imgA.getInt(p.x, p.y); |
46 | new MultiSet<Rect> matches; |
47 | for y to h: for x to w: |
48 | if (rgbDiff(col, imgB.getInt(x, y)) <= ppt) { |
49 | Rect r1 = new Rect(p.x, p.y, 1, 1); |
50 | Rect r2 = new Rect(x, y, 1, 1); |
51 | Rect r = translateRect(rgbExpandMatch(imgA, imgB, r1, r2, ppt), -p.x, -p.y); |
52 | matches.add(r); |
53 | } |
54 | L<Rect> matchesList = sortByCalculatedFieldDesc(keys(matches), f rectPixels); |
55 | Rect r = first(matchesList); |
56 | if (r != null) |
57 | print("Largest match: " + rectPixels(r) + " pixels. " + n(matchesList, "matches") + ": " + matchesList); |
58 | else |
59 | print("No match"); |
60 | grab.sizes.addAll(matches); |
61 | grab.change(); |
62 | } |
63 | print("Done finding"); |
64 | } |
65 | |
66 | static int visW = 200, visH = 200; |
67 | |
68 | svoid visualize(Grab grab) { |
69 | RGBImage img = new RGBImage(grab.screenshot->getImage()); |
70 | Collection<Rect> rects = keys(grab.sizes); |
71 | Pt p = grab.point; |
72 | Rect clip = intersectRects(new Rect(0, 0, img.w(), img.h()), new Rect(p.x-visW/2, p.y-visH/2, visW, visH)); |
73 | img = img.clip(clip); |
74 | rgbMarkPoint(img, p.x-clip.x, p.y-clip.y); |
75 | rects = translateRects(rects, p.x-clip.x, p.y-clip.y); |
76 | quickShowImage("Grab " + grab.id, rgbVisualizeRectsZoomed(img, rects)); |
77 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1006864 |
Snippet name: | New Auto Segment [phase 1, dev.] |
Eternal ID of this version: | #1006864/25 |
Text MD5: | 48b1ae164384fd56b5404d0e87f6a2db |
Transpilation MD5: | a39a71b10f2b764a163849e176a69942 |
Author: | stefan |
Category: | javax / ocr / big data |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-02-13 00:44:32 |
Source code size: | 2359 bytes / 77 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 542 / 956 |
Version history: | 24 change(s) |
Referenced in: | [show references] |