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

57
LINES

< > BotCompany Repo | #1004155 // Precise Image Search in Screenshot (works, but who wants that much precision?)

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

Uses 9620K of libraries. Click here for Pure Java version (317L/3K/10K).

!752

lib 1003153 // magic.jar

import prophecy.common.image.ImageSurface;
import prophecy.common.image.RGBImage;
import prophecy.common.image.BWImage;

static new HashMap<S, BWImage> images;

sclass FoundImg {
  Rectangle r;
  S imageID;
  
  *() {}
  *(Rectangle *r, S *imageID) {}
}

static new L<FoundImg> found;

p {
  BWImage big = shootScreenBW();
  S patID = "#1004153";  // Search Button
  BWImage pat = loadBWImage(patID);
  
  int wp = pat.getWidth(), hp = pat.getHeight();
  int w = big.getWidth(), h = big.getHeight();
  for (int y = 0; y < h-hp; y++)
    for (int x = 0; x < w-wp; x++)
      if (imagesSimilar(big, pat, x, y)) {
        print("Found at " + x + "/" + y);
        found.add(new FoundImg(new Rectangle(x, y, wp, hp), patID));
        x += wp-1;
      }
}

static bool imagesSimilar(BWImage big, BWImage pat, int x, int y) {
  int wp = pat.getWidth(), hp = pat.getHeight();
  int w = big.getWidth(), h = big.getHeight();
  for (int yy = 0; yy < hp; yy++)
    for (int xx = 0; xx < wp; xx++)
      if (big.getPixel(x+xx, y+yy) != pat.getPixel(xx, yy))
        false;
  true;
}

static float imageSimilarity(BWImage big, BWImage pat, int x, int y, float max) {
  int wp = pat.getWidth(), hp = pat.getHeight();
  int w = big.getWidth(), h = big.getHeight();
  float diff = 0;
  for (int yy = 0; yy < hp; yy++)
    for (int xx = 0; xx < wp; xx++) {
      diff += abs(big.getPixel(x+xx, y+yy)-pat.getPixel(xx, yy));
      if (diff >= max) ret diff;
    }
  ret diff;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004155
Snippet name: Precise Image Search in Screenshot (works, but who wants that much precision?)
Eternal ID of this version: #1004155/1
Text MD5: 58b4de489ce4ced8e9b4772b84ac178e
Transpilation MD5: 67b470c4acab9fb9ffcb3b9ff1a5feca
Author: stefan
Category: javax / gui
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-13 14:21:50
Source code size: 1546 bytes / 57 lines
Pitched / IR pitched: No / No
Views / Downloads: 508 / 598
Referenced in: [show references]