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

48
LINES

< > BotCompany Repo | #1005929 // Find selection boxes in ImageSurface by OCR [dev.]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (4475L/30K/102K).

!752

static Color inner = Color.green, outer = Color.white;

p {
  ShootLoop loop = new ShootLoop {
    void recognize() {
      selections.clear();
      float xInner = new RGB(outer).getBrightness();
      float xOuter = new RGB(outer).getBrightness();
      print("xInner=" + xInner + ", xOuter=" + xOuter);
      BWImage screen = screen();
      for (int y = 0; y < screenHeight-1; y++)
        for x to screenWidth:
          if (screen.getPixel(x, y) == xOuter) {
            Rect r = followRect(x, y, xOuter);
            if (r != null && r.w > 1 && r.h > 1) {
              print("Found outer: " + r);
              Rect r2 = followRect(x+1, y+1, xInner);
              if (r2.w+2 == r.w && r2.h+2 == r.h)
                selections.add(r);
            }
            while (x < screenWidth && screen.getPixel(x, y) == xOuter) ++x;
          }

      printStruct(+selections);
      showThumbnail();
    }
  
    Rect followRect(int x1, int y1, float c) {
      BWImage screen = screen();
      int x = x1, y = y1;
      while (x+1 < screenWidth && screen.getPixel(x+1, y) == c
        && screen.getPixel(x, y+1) != c) ++x;
      while (y+1 < screenHeight && screen.getPixel(x, y+1) == c) ++y;
      int x2 = x, y2 = y;
      print("Got " + c + " " + (x2-x1) + "/" + (y2-y1) + " from " + x1 + "/" + y1);
      while (x > x1 && screen.getPixel(x-1, y) == c) --x;
      if (x != x1) null;
      while (y > y1 && screen.getPixel(x, y-1) == c) --y;
      if (y != y1) null;
      ret pointsRect(x1, y1, x2+1, y2+1);
    }
  };
  
  loop.doSingle(loadBufferedImage("#1005930"));
  //loop.run();
}

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: #1005929
Snippet name: Find selection boxes in ImageSurface by OCR [dev.]
Eternal ID of this version: #1005929/1
Text MD5: 47c1a8cfbaac6bab12b98696a1187326
Transpilation MD5: fd490a095f064a1e2966c616c98c31f8
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:37:51
Source code size: 1646 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 481 / 548
Referenced in: [show references]