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

39
LINES

< > BotCompany Repo | #1015534 // areasColoredOneOf

JavaX fragment (include)

static L<Rect> areasColoredOneOf(Color... color) {
  ret areasColoredOneOf(shootScreen(), color);
}

static int areasColoredOneOf_g = 3;

static L<Rect> areasColoredOneOf(RGBImage img, int... color) {
  ret areasColoredOneOf(img, mapToArrayOfType(Color.class, f toColor, asList(color)));
}

static L<Rect> areasColoredOneOf(int... color) {
  ret areasColoredOneOf(mapToArrayOfType(Color.class, f toColor, asList(color)));
}

static L<Rect> areasColoredOneOf(RGBImage img, Color... color) {
  ret areasColoredOneOf(img, areasColoredOneOf_g, color);
}

static L<Rect> areasColoredOneOf(RGBImage img, int g, Color... color) {
  int w = img.w(), h = img.h();
  int gw = w/g, gh = h/g;

  new BitSet grid;
  int[] intColors = mapToIntArray(func(Color c) -> Int { c.getRGB() & 0xFFFFFF }, color);
  int overlap = 0;

  for (int gy = 0; gy <= h- g; gy += g)
    next: for (int gx = 0; gx <= w- g; gx += g) {
      float min = 1, max = 0;
      int y2 = min(h, gy + g + overlap);
      int x2 = min(w, gx + g + overlap);
      if (rgbAllPixelsInAreaEqualToOneOf(img, gx, gy, x2, y2, intColors))
        grid.set((gy / g) * gw + (gx / g));
    }

  L<Rect> clips = floodFillGrid(grid, gw, gh, g);
  //print(n(clips, "areas") + " found for color " + new RGB(color) + ": " + struct(clips));
  ret clips;
}

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: 359 / 407
Version history: 8 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)