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

!7

p {
  RGBImage a = null, b = rgbShootScreen();
  repeat {
    sleep(500);
    time {
      a = b;
      b = rgbShootScreen();
      
      print("*");
      compare(a, b);
    }
  }
}

svoid compare(RGBImage a, RGBImage b) {
  //new HashSet<Pt> deltas;
  new Best<Rect> best;
  for tries to 10: {
    Rect r = randomScreenRect(50, 50);
    RGBImage clip = a.clip(r);
    if (rgbInnerPrecision(clip) >= 0.5f) {
      Rect r2 = rgbSearchPrecise(b, clip);
      if (r2 != null && neq(r, r2)) {
        Pt delta = new Pt(r2.x-r.x, r2.y-r.y);
        Rect match = expandMatch(a, b, r, r2);
        best.put(match, match.w*match.h);
        //print("Movement: " + delta + ". Match size: " + );
      }
    }
  }
  Rect r = best.get();
  if (r != null)
    quickShowImage(rgbScale(a.clip(r), 0.5));
}

static Rect expandMatch(RGBImage a, RGBImage b, Rect r1, Rect r2) {
  assertEquals(r1.w, r2.w);
  assertEquals(r1.h, r2.h);
  //do {
    Rect r = r2;
    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))) {
      r1 = growRectLeft(r1, 1); r2 = growRectLeft(r2, 1);
    }
  ret r2;
}

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: 482 / 611
Version history: 5 change(s)
Referenced in: #1006820 - Find Motion In Test Screenshots [probably works, shows most of moved window]