Libraryless. Click here for Pure Java version (4296L/29K/97K).
1 | !752 |
2 | |
3 | p { |
4 | BWImage img = shootScreenBW(); |
5 | print(go(img)); |
6 | setFrameTitle("g = " + g, showImageWithSelections(img.getBufferedImage(), clips)); |
7 | g = 3; |
8 | print(go(img)); |
9 | setFrameTitle("g = " + g, showImageWithSelections(img.getBufferedImage(), clips)); |
10 | } |
11 | |
12 | static L<Rect> clips; |
13 | static int[] grid; |
14 | static int gw, gh; |
15 | static int g = 4; |
16 | |
17 | static Rect fill(int x, int y, Rect r) { |
18 | if (x < 0 || y < 0 || x >= gw || y >= gh) |
19 | return r; |
20 | int idx = y*gw+x; |
21 | if (grid[idx] == 0) |
22 | return r; |
23 | grid[idx] = 0; |
24 | Rect me = new Rect(x, y, 1, 1); |
25 | if (r == null) |
26 | r = me; |
27 | else |
28 | r = rectUnion(r, me); |
29 | |
30 | r = fill(x-1, y, r); |
31 | r = fill(x+1, y, r); |
32 | r = fill(x, y-1, r); |
33 | r = fill(x, y+1, r); |
34 | return r; |
35 | } |
36 | |
37 | static S go(BWImage img) { |
38 | int w = img.getWidth(), h = img.getHeight(); |
39 | gw = w/g; |
40 | gh = h/g; // width & height of grid |
41 | |
42 | grid = new int[gw*gh]; |
43 | |
44 | for (int gy = 0; gy <= h- g; gy += g) |
45 | next: for (int gx = 0; gx <= w- g; gx += g) { |
46 | float min = 1, max = 0; |
47 | for (int y = gy; y < gy + g; y++) |
48 | for (int x = gx; x < gx + g; x++) { |
49 | float b = img.getPixel(x, y); |
50 | min = Math.min(min, b); |
51 | max = Math.max(max, b); |
52 | if (min < 0.5 && max > 0.5) { |
53 | grid[(gy / g) * gw + (gx / g)] = 2; |
54 | continue next; |
55 | } |
56 | } |
57 | } |
58 | |
59 | new L<S> result; |
60 | clips = new L; |
61 | |
62 | for (int y = 0; y < gh; y++) |
63 | for (int x = 0; x < gw; x++) { |
64 | Rect r = fill(x, y, null); |
65 | if (r != null) { |
66 | r = scaleRect(r, g); |
67 | clips.add(r); |
68 | r = autoCropOfBWImage(img, r); |
69 | |
70 | BWImage cropped = img.clip(r); |
71 | String hash = md5OfBWImage(cropped); |
72 | |
73 | result.add(r + " -> " + hash); |
74 | } |
75 | } |
76 | |
77 | return "Floodfill: " + join("|", result); |
78 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005836 |
Snippet name: | Test Auto-Segmenting ["Lua411", dev.] |
Eternal ID of this version: | #1005836/1 |
Text MD5: | 22d5afdb572c824456d748a1e2867381 |
Transpilation MD5: | 28925e03f4fab9a09b3fc75de6f59bfb |
Author: | stefan |
Category: | javax / ocr |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-12-11 02:39:48 |
Source code size: | 1836 bytes / 78 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 523 / 622 |
Referenced in: | [show references] |