Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

39
LINES

< > BotCompany Repo | #1015534 // areasColoredOneOf

JavaX fragment (include)

1  
static L<Rect> areasColoredOneOf(Color... color) {
2  
  ret areasColoredOneOf(shootScreen(), color);
3  
}
4  
5  
static int areasColoredOneOf_g = 3;
6  
7  
static L<Rect> areasColoredOneOf(RGBImage img, int... color) {
8  
  ret areasColoredOneOf(img, mapToArrayOfType(Color.class, f toColor, asList(color)));
9  
}
10  
11  
static L<Rect> areasColoredOneOf(int... color) {
12  
  ret areasColoredOneOf(mapToArrayOfType(Color.class, f toColor, asList(color)));
13  
}
14  
15  
static L<Rect> areasColoredOneOf(RGBImage img, Color... color) {
16  
  ret areasColoredOneOf(img, areasColoredOneOf_g, color);
17  
}
18  
19  
static L<Rect> areasColoredOneOf(RGBImage img, int g, Color... color) {
20  
  int w = img.w(), h = img.h();
21  
  int gw = w/g, gh = h/g;
22  
23  
  new BitSet grid;
24  
  int[] intColors = mapToIntArray(func(Color c) -> Int { c.getRGB() & 0xFFFFFF }, color);
25  
  int overlap = 0;
26  
27  
  for (int gy = 0; gy <= h- g; gy += g)
28  
    next: for (int gx = 0; gx <= w- g; gx += g) {
29  
      float min = 1, max = 0;
30  
      int y2 = min(h, gy + g + overlap);
31  
      int x2 = min(w, gx + g + overlap);
32  
      if (rgbAllPixelsInAreaEqualToOneOf(img, gx, gy, x2, y2, intColors))
33  
        grid.set((gy / g) * gw + (gx / g));
34  
    }
35  
36  
  L<Rect> clips = floodFillGrid(grid, gw, gh, g);
37  
  //print(n(clips, "areas") + " found for color " + new RGB(color) + ": " + struct(clips));
38  
  ret clips;
39  
}

Author comment

Began life as a copy of #1006215

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: #1015534
Snippet name: areasColoredOneOf
Eternal ID of this version: #1015534/9
Text MD5: 4aef42314a71a3c9dcdf977c6df59861
Author: stefan
Category: javax / ocr
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-16 12:10:51
Source code size: 1334 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 279 / 336
Version history: 8 change(s)
Referenced in: [show references]