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

47
LINES

< > BotCompany Repo | #1006814 // Find Motion [dev.]

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

Libraryless. Click here for Pure Java version (5140L/36K/128K).

1  
!7
2  
3  
p {
4  
  RGBImage a = null, b = rgbShootScreen();
5  
  repeat {
6  
    sleep(500);
7  
    time {
8  
      a = b;
9  
      b = rgbShootScreen();
10  
      
11  
      print("*");
12  
      compare(a, b);
13  
    }
14  
  }
15  
}
16  
17  
svoid compare(RGBImage a, RGBImage b) {
18  
  //new HashSet<Pt> deltas;
19  
  new Best<Rect> best;
20  
  for tries to 10: {
21  
    Rect r = randomScreenRect(50, 50);
22  
    RGBImage clip = a.clip(r);
23  
    if (rgbInnerPrecision(clip) >= 0.5f) {
24  
      Rect r2 = rgbSearchPrecise(b, clip);
25  
      if (r2 != null && neq(r, r2)) {
26  
        Pt delta = new Pt(r2.x-r.x, r2.y-r.y);
27  
        Rect match = expandMatch(a, b, r, r2);
28  
        best.put(match, match.w*match.h);
29  
        //print("Movement: " + delta + ". Match size: " + );
30  
      }
31  
    }
32  
  }
33  
  Rect r = best.get();
34  
  if (r != null)
35  
    quickShowImage(rgbScale(a.clip(r), 0.5));
36  
}
37  
38  
static Rect expandMatch(RGBImage a, RGBImage b, Rect r1, Rect r2) {
39  
  assertEquals(r1.w, r2.w);
40  
  assertEquals(r1.h, r2.h);
41  
  //do {
42  
    Rect r = r2;
43  
    while (r2.x > 0 && r1.x > 0 && rgbImageSectionsIdentical(a, new Rect(r1.x-1, r1.y, 1, r1.h), b, new Rect(r2.x-1, r2.y, 1, r2.h))) {
44  
      r1 = growRectLeft(r1, 1); r2 = growRectLeft(r2, 1);
45  
    }
46  
  ret r2;
47  
}

Author comment

Began life as a copy of #1006798

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: #1006814
Snippet name: Find Motion [dev.]
Eternal ID of this version: #1006814/6
Text MD5: 02064f34cbce7aa91429fd3da3af8303
Transpilation MD5: e105e816f9dd7db56645953d785ff9a9
Author: stefan
Category: javax / ocr
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-05 03:55:56
Source code size: 1206 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 420 / 525
Version history: 5 change(s)
Referenced in: [show references]