1 | !752 |
2 | |
3 | static Color inner = Color.green, outer = Color.white; |
4 | |
5 | p { |
6 | ShootLoop loop = new ShootLoop { |
7 | void recognize() { |
8 | selections.clear(); |
9 | float xInner = new RGB(outer).getBrightness(); |
10 | float xOuter = new RGB(outer).getBrightness(); |
11 | print("xInner=" + xInner + ", xOuter=" + xOuter); |
12 | BWImage screen = screen(); |
13 | for (int y1 = 0; y < screenHeight-3; y1++) |
14 | for (int x1 = 0; x < screenWidth-1; x1++) |
15 | if (screen.getPixel(x1, y1) == xOuter |
16 | && screen.getPixel(x1+1, y1+1) == xInner |
17 | && screen.getPixel(x1, y1+1) == xOuter |
18 | && screen.getPixel(x1+1, y1) == xOuter) { |
19 | |
20 | int x = x1, y = y1; |
21 | while (x+1 < screenWidth |
22 | && screen.getPixel(x+1, y) == xOuter |
23 | && screen.getPixel(x+1, y+1) == xInner) ++x; |
24 | ++x; |
25 | if (!(screen.getPixel(x, y) == xOuter |
26 | && screen.getPixel(x, y+1) == xOuter)) { |
27 | x1 = x; |
28 | continue; |
29 | } |
30 | |
31 | && screen.getPixel(x, y+1) != c) ++x; |
32 | while (y+1 < screenHeight && screen.getPixel(x, y+1) == c) ++y; |
33 | int x2 = x, y2 = y; |
34 | print("Got " + c + " " + (x2-x1) + "/" + (y2-y1)); |
35 | while (x > x1 && screen.getPixel(x-1, y) == c) --x; |
36 | if (x != x1) null; |
37 | while (y > y1 && screen.getPixel(x, y-1) == c) --y; |
38 | if (y != y1) null; |
39 | ret pointsRect(x1, y1, x2+1, y2+1); |
40 | Rect r = followRect(x, y, xOuter); |
41 | if (r != null && r.w > 1 && r.h > 1) { |
42 | print("Found outer: " + r); |
43 | Rect r2 = followRect(x+1, y+1, xInner); |
44 | if (r2.w+2 == r.w && r2.h+2 == r.h) |
45 | selections.add(r); |
46 | } |
47 | while (x < screenWidth && screen.getPixel(x, y) == xOuter) ++x; |
48 | } |
49 | |
50 | printStruct(+selections); |
51 | showThumbnail(); |
52 | } |
53 | |
54 | Rect followRect(int x1, int y1, float c) { |
55 | BWImage screen = screen(); |
56 | int x = x1, y = y1; |
57 | while (x+1 < screenWidth && screen.getPixel(x+1, y) == c |
58 | && screen.getPixel(x, y+1) != c) ++x; |
59 | while (y+1 < screenHeight && screen.getPixel(x, y+1) == c) ++y; |
60 | int x2 = x, y2 = y; |
61 | print("Got " + c + " " + (x2-x1) + "/" + (y2-y1)); |
62 | while (x > x1 && screen.getPixel(x-1, y) == c) --x; |
63 | if (x != x1) null; |
64 | while (y > y1 && screen.getPixel(x, y-1) == c) --y; |
65 | if (y != y1) null; |
66 | ret pointsRect(x1, y1, x2+1, y2+1); |
67 | } |
68 | }; |
69 | |
70 | loop.doSingle(loadBufferedImage("#1005930")); |
71 | //loop.run(); |
72 | } |
Began life as a copy of #1005929
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: | #1005931 |
Snippet name: | Find selection boxes in ImageSurface by OCR [v2, dev.] |
Eternal ID of this version: | #1005931/1 |
Text MD5: | 9c1cbcf6b9464fb34b6003e5a0340350 |
Author: | stefan |
Category: | javax / ocr |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-12-12 22:30:17 |
Source code size: | 2594 bytes / 72 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 522 / 575 |
Referenced in: | [show references] |