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

64
LINES

< > BotCompany Repo | #1006870 // New Algorithm [phase 1, dev.]

JavaX source code - run with: x30.jar

1  
!7
2  
3  
concept Screenshot {
4  
  new Ref<PNGFile> file;
5  
  Image332 preview;
6  
}
7  
8  
concept Grab {
9  
  new Ref<Screenshot> screenshot;
10  
  Pt point;
11  
  new MultiSet<Rect> sizes;
12  
}
13  
14  
p-substance-thread {
15  
  db();
16  
  awt {
17  
    showFrame(jtabs(
18  
      "Shoot" := makeConceptTable(Screenshot),
19  
      "Mark" := makeConceptTable(Screenshot),
20  
      "Find" := makeConceptTable(Grab)
21  
    ));
22  
  }
23  
}
24  
25  
svoid grab {
26  
  trackOneClick(voidfunc(final Point p) {
27  
    thread {
28  
      sleep(500); // allow screen behind red dot to be repainted
29  
      Grab grab = cnew(Grab,
30  
        screenshot := new PNGFile(shootScreenBufferedImage()),
31  
        point := new Pt(p)
32  
      );
33  
      infoBox("Grabbed! " + grab.id);
34  
    }
35  
  });
36  
}
37  
38  
svoid find {
39  
  float ppt = 0.1f; // per pixel tolerance
40  
  RGBImage imgB = rgbShootScreen();
41  
  int w = imgB.w(), h = imgB.h();
42  
  for (Grab grab) {
43  
    print ("Searching " + grab.id + "...");
44  
    RGBImage imgA = new RGBImage(grab.screenshot->getImage());
45  
    Pt p = grab.point;
46  
    int col = imgA.getInt(p.x, p.y);
47  
    new MultiSet<Rect> matches;
48  
    for y to h: for x to w:
49  
      if (rgbDiff(col, imgB.getInt(x, y)) <= ppt) {
50  
        Rect r1 = new Rect(p.x, p.y, 1, 1);
51  
        Rect r2 = new Rect(x, y, 1, 1);
52  
        Rect r = translateRect(rgbExpandMatch(imgA, imgB, r1, r2, ppt), -p.x, -p.y);
53  
        matches.add(r);
54  
      }
55  
    L<Rect> matchesList = sortByCalculatedFieldDesc(keys(matches), f rectPixels);
56  
    Rect r = first(matchesList);
57  
    if (r != null)
58  
      print("Largest match: " + rectPixels(r) + " pixels. " + n(matchesList, "matches") + ": " + matchesList);
59  
    else
60  
      print("No match");
61  
    grab.sizes.addAll(matches);
62  
    grab.change();
63  
  }
64  
}

Author comment

Began life as a copy of #1006864

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: #1006870
Snippet name: New Algorithm [phase 1, dev.]
Eternal ID of this version: #1006870/1
Text MD5: 9f58f744a1a0736b5d208b54fd844683
Author: stefan
Category: javax / ocr / big data
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-11 07:02:03
Source code size: 1708 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 489 / 471
Referenced in: [show references]