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

32
LINES

< > BotCompany Repo | #1005396 // bwRawImageSearch

JavaX fragment (include)

1  
sbool bwRawImageSearch_verbose;
2  
static BWImageSectionComparator bwRawImageSearch_comparator;
3  
static int bwRawImageSearch_maxEntries = 1000;
4  
5  
static L<FoundImg> bwRawImageSearch(BWImage big, BWImage pat, float similarity) {
6  
  ret bwRawImageSearch(big, pat, similarity, bwRawImageSearch_maxEntries);
7  
}
8  
9  
// similarity = e.g. 0.99f
10  
static L<FoundImg> bwRawImageSearch(BWImage big, BWImage pat, float similarity, int maxEntries) {
11  
  new L<FoundImg> found;
12  
  int wp = pat.getWidth(), hp = pat.getHeight();
13  
  int w = big.getWidth(), h = big.getHeight();
14  
  float maxError = (1f-similarity)*wp*hp;
15  
  for (int y = 0; y < h-hp; y++)
16  
    for (int x = 0; x < w-wp; x++) {
17  
      float diff = bwRawImageSearch_comparator != null
18  
         ? bwRawImageSearch_comparator.compare(big, pat, x, y, maxError)
19  
         : bwImageSectionsSimilarity(big, pat, x, y, maxError);
20  
      if (diff <= maxError) {
21  
        float sim = 1-diff/(wp*hp);
22  
        if (bwRawImageSearch_verbose)
23  
          print("  Image found at " + x + "/" + y + " [sim: " + formatDouble(sim, 4) + "]");
24  
        Rect r = new Rect(x, y, wp, hp);
25  
        found.add(new FoundImg(r, sim));
26  
        ping();
27  
        if (l(found) >= maxEntries) ret found;
28  
        x += wp-1;
29  
      }
30  
    }
31  
  ret found;
32  
}

Author comment

Began life as a copy of #1005386

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1005396
Snippet name: bwRawImageSearch
Eternal ID of this version: #1005396/1
Text MD5: dbc804fb86a120da0f6a54f8fd96a083
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-09 02:16:12
Source code size: 1271 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 614 / 611
Referenced in: [show references]