Uses 3874K of libraries. Click here for Pure Java version (11693L/83K/287K).
!7 concept Grab { new Ref<PNGFile> screenshot; Pt point; new MultiSet<Rect> sizes; } p-substance-thread { shootScreen_useScrot = true; // method without black spots db(); awt { showControls(jCenteredLine( jbutton("Grab", "grab"), jbutton("Find", rThread("find")))); final JTable table = showConceptsTable(Grab); addToWindow(table, tableDependButton(table, "Show", r { visualize(selectedConcept(table, Grab)); })); } } svoid grab { trackOneClick(voidfunc(final Point p) { thread { sleep(500); // allow screen behind red dot to be repainted Grab grab = cnew(Grab, screenshot := new PNGFile(shootScreenBufferedImage()), point := new Pt(p) ); infoBox("Grabbed! " + grab.id); } }); } svoid find { float ppt = 0.1f; // per pixel tolerance RGBImage imgB = rgbShootScreen(); int w = imgB.w(), h = imgB.h(); for (Grab grab) { print ("Searching " + grab.id + "..."); RGBImage imgA = new RGBImage(grab.screenshot->getImage()); Pt p = grab.point; int col = imgA.getInt(p.x, p.y); new MultiSet<Rect> matches; for y to h: for x to w: if (rgbDiff(col, imgB.getInt(x, y)) <= ppt) { Rect r1 = new Rect(p.x, p.y, 1, 1); Rect r2 = new Rect(x, y, 1, 1); Rect r = translateRect(rgbExpandMatch(imgA, imgB, r1, r2, ppt), -p.x, -p.y); matches.add(r); } L<Rect> matchesList = sortByCalculatedFieldDesc(keys(matches), f rectPixels); Rect r = first(matchesList); if (r != null) print("Largest match: " + rectPixels(r) + " pixels. " + n(matchesList, "matches") + ": " + matchesList); else print("No match"); grab.sizes.addAll(matches); grab.change(); } print("Done finding"); } static int visW = 200, visH = 200; svoid visualize(Grab grab) { RGBImage img = new RGBImage(grab.screenshot->getImage()); Collection<Rect> rects = keys(grab.sizes); Pt p = grab.point; Rect clip = intersectRects(new Rect(0, 0, img.w(), img.h()), new Rect(p.x-visW/2, p.y-visH/2, visW, visH)); img = img.clip(clip); rgbMarkPoint(img, p.x-clip.x, p.y-clip.y); rects = translateRects(rects, p.x-clip.x, p.y-clip.y); quickShowImage("Grab " + grab.id, rgbVisualizeRectsZoomed(img, rects)); }
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: | 498 / 899 |
Version history: | 24 change(s) |
Referenced in: | #1006870 - New Algorithm [phase 1, dev.] #1006876 - Fix unstructure bug [dev.] |