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).

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 y = 0; y < screenHeight-1; y++)
14  
        for x to screenWidth:
15  
          if (screen.getPixel(x, y) == xOuter) {
16  
            Rect r = followRect(x, y, xOuter);
17  
            if (r != null && r.w > 1 && r.h > 1) {
18  
              print("Found outer: " + r);
19  
              Rect r2 = followRect(x+1, y+1, xInner);
20  
              if (r2.w+2 == r.w && r2.h+2 == r.h)
21  
                selections.add(r);
22  
            }
23  
            while (x < screenWidth && screen.getPixel(x, y) == xOuter) ++x;
24  
          }
25  
26  
      printStruct(+selections);
27  
      showThumbnail();
28  
    }
29  
  
30  
    Rect followRect(int x1, int y1, float c) {
31  
      BWImage screen = screen();
32  
      int x = x1, y = y1;
33  
      while (x+1 < screenWidth && screen.getPixel(x+1, y) == c
34  
        && screen.getPixel(x, y+1) != c) ++x;
35  
      while (y+1 < screenHeight && screen.getPixel(x, y+1) == c) ++y;
36  
      int x2 = x, y2 = y;
37  
      print("Got " + c + " " + (x2-x1) + "/" + (y2-y1) + " from " + x1 + "/" + y1);
38  
      while (x > x1 && screen.getPixel(x-1, y) == c) --x;
39  
      if (x != x1) null;
40  
      while (y > y1 && screen.getPixel(x, y-1) == c) --y;
41  
      if (y != y1) null;
42  
      ret pointsRect(x1, y1, x2+1, y2+1);
43  
    }
44  
  };
45  
  
46  
  loop.doSingle(loadBufferedImage("#1005930"));
47  
  //loop.run();
48  
}

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: 550 / 645
Referenced in: [show references]