Libraryless. Click here for Pure Java version (7505L/44K).
1 | sclass ULetterbox1 implements IIIRecognizer<DoubleRect> { |
2 | public void run( |
3 | IProbabilisticScheduler scheduler, |
4 | URecognizer.Cell cell, |
5 | IVF1<DoubleRect> valueToAction) { |
6 | var whole = cell; |
7 | var middle = cell.slice(1, 1.0/3.0, 2.0/3.0); |
8 | |
9 | // We assume the border is black. |
10 | // If the picture fills the whole screen, it will tend |
11 | // to equal brightness everywhere. Thus whole = middle*3 |
12 | // (because it's 3 times as large). |
13 | // If only "middle" is not black, we have whole = middle. |
14 | // Thus the border position can be estimated as: |
15 | |
16 | double wholePixelSum = whole.pixelSum(); |
17 | double middlePixelSum = middle.pixelSum(); |
18 | double ratio = doubleRatio(wholePixelSum, middlePixelSum); |
19 | double borderPos = transformBetweenDoubleRanges_verbose(ratio, |
20 | doubleRange(3, 1), doubleRange(0, 1/3.0)); |
21 | printVars(+wholePixelSum, +middlePixelSum, +ratio, +borderPos); |
22 | |
23 | DoubleRect rect = cell.slice(1, borderPos, 1-borderPos).rawDoubleRect(); |
24 | |
25 | // No probabilities used. |
26 | |
27 | scheduler.schedule(1.0, () -> valueToAction.get(rect)); |
28 | |
29 | //var antiBorder = cell.slice(1, 1.0/8.0, 1-1/8.0); |
30 | //var border = whole.pixelSum()-antiBorder.pixelSum(); |
31 | } |
32 | } |
Began life as a copy of #1032079
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1032085 |
Snippet name: | ULetterbox1 - detect a letterbox [pixelSum version, works!] |
Eternal ID of this version: | #1032085/1 |
Text MD5: | 3d6080ce16ba21f23f38a7bc1a5eac37 |
Transpilation MD5: | 4c5c1bd1668c4b321b1f7572016cb38a |
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:37:42 |
Source code size: | 1252 bytes / 32 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 153 / 209 |
Referenced in: | [show references] |