Uses 9620K of libraries. Click here for Pure Java version (317L/3K/10K).
1 | !752 |
2 | |
3 | lib 1003153 // magic.jar |
4 | |
5 | import prophecy.common.image.ImageSurface; |
6 | import prophecy.common.image.RGBImage; |
7 | import prophecy.common.image.BWImage; |
8 | |
9 | static new HashMap<S, BWImage> images; |
10 | |
11 | sclass FoundImg { |
12 | Rectangle r; |
13 | S imageID; |
14 | |
15 | *() {} |
16 | *(Rectangle *r, S *imageID) {} |
17 | } |
18 | |
19 | static new L<FoundImg> found; |
20 | |
21 | p { |
22 | BWImage big = shootScreenBW(); |
23 | S patID = "#1004153"; // Search Button |
24 | BWImage pat = loadBWImage(patID); |
25 | |
26 | int wp = pat.getWidth(), hp = pat.getHeight(); |
27 | int w = big.getWidth(), h = big.getHeight(); |
28 | for (int y = 0; y < h-hp; y++) |
29 | for (int x = 0; x < w-wp; x++) |
30 | if (imagesSimilar(big, pat, x, y)) { |
31 | print("Found at " + x + "/" + y); |
32 | found.add(new FoundImg(new Rectangle(x, y, wp, hp), patID)); |
33 | x += wp-1; |
34 | } |
35 | } |
36 | |
37 | static bool imagesSimilar(BWImage big, BWImage pat, int x, int y) { |
38 | int wp = pat.getWidth(), hp = pat.getHeight(); |
39 | int w = big.getWidth(), h = big.getHeight(); |
40 | for (int yy = 0; yy < hp; yy++) |
41 | for (int xx = 0; xx < wp; xx++) |
42 | if (big.getPixel(x+xx, y+yy) != pat.getPixel(xx, yy)) |
43 | false; |
44 | true; |
45 | } |
46 | |
47 | static float imageSimilarity(BWImage big, BWImage pat, int x, int y, float max) { |
48 | int wp = pat.getWidth(), hp = pat.getHeight(); |
49 | int w = big.getWidth(), h = big.getHeight(); |
50 | float diff = 0; |
51 | for (int yy = 0; yy < hp; yy++) |
52 | for (int xx = 0; xx < wp; xx++) { |
53 | diff += abs(big.getPixel(x+xx, y+yy)-pat.getPixel(xx, yy)); |
54 | if (diff >= max) ret diff; |
55 | } |
56 | ret diff; |
57 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004155 |
Snippet name: | Precise Image Search in Screenshot (works, but who wants that much precision?) |
Eternal ID of this version: | #1004155/1 |
Text MD5: | 58b4de489ce4ced8e9b4772b84ac178e |
Transpilation MD5: | 67b470c4acab9fb9ffcb3b9ff1a5feca |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-11-13 14:21:50 |
Source code size: | 1546 bytes / 57 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 509 / 601 |
Referenced in: | [show references] |