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

34
LINES

< > BotCompany Repo | #1032079 // ULetterbox1 - detect a letterbox

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (7511L/44K).

1  
sclass ULetterbox1 implements IIIRecognizer<DoubleRect> {
2  
  public void run(
3  
    IProbabilisticScheduler scheduler,
4  
    URecognizer.Cell cell,
5  
    IVF1<DoubleRect> valueToAction) {
6  
    
7  
    // We inquire 2 pixels from the image.
8  
    
9  
    var whole  = cell;
10  
    var middle = cell.slice(1, 1.0/3.0, 2.0/3.0);
11  
    
12  
    double wholeColor = whole!;
13  
    double middleColor = middle!;
14  
    
15  
    // Inquiry done. In ULetterbox1, we assume the border is black.
16  
    // (We could verify this by doing a third pixel query,
17  
    // but surely that's too slow.!)
18  
    // Here's the logic.
19  
    // If the picture fills the whole screen, it will tend
20  
    // to equal brightness everywhere. Thus whole = middle*3
21  
    // (because it's 3 times as large).
22  
    // If only "middle" is not black, we have whole = middle.
23  
    // Thus the border position can be estimated as:
24  
    double ratio = doubleRatio(wholeColor, middleColor);
25  
    double borderPos = transformBetweenDoubleRanges_verbose(ratio, 1, 1/3.0, 0, 1/3.0);
26  
    printVars(+wholeColor, +middleColor, +ratio, +borderPos);
27  
      
28  
    DoubleRect rect = cell.slice(1, borderPos, 1-borderPos).rawDoubleRect();
29  
    
30  
    // No probabilities used.
31  
    
32  
    scheduler.schedule(1.0, () -> valueToAction.get(rect));
33  
  }
34  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032079
Snippet name: ULetterbox1 - detect a letterbox
Eternal ID of this version: #1032079/20
Text MD5: 250e7e9f4db95622ac35479d9cdfd4f7
Transpilation MD5: 39588b0d6ec4fff99013eb7d20639678
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-11 13:48:47
Source code size: 1276 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 228 / 424
Version history: 19 change(s)
Referenced in: [show references]