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

25
LINES

< > BotCompany Repo | #1005709 // horizontalAutoSplit [uses column average brightness, for black on white text]

JavaX fragment (include)

1  
static float horizontalAutoSplit_threshold = 0.99f;
2  
3  
static L<Rect> horizontalAutoSplit(BWImage img) {
4  
  ret horizontalAutoSplit(img, horizontalAutoSplit_threshold);
5  
}
6  
7  
static L<Rect> horizontalAutoSplit(BWImage img, float threshold) {
8  
  int w = img.getWidth(), h = img.getHeight();
9  
  float[] f = bwImageColumnBrightnesses(img);
10  
  
11  
  new L<Rect> l;
12  
  int j = -1;
13  
  for (int i = 0; i < l(f); i++)
14  
    if (f[i] < threshold) { // start / continue streak
15  
      if (j < 0) j = i; 
16  
    } else {
17  
      if (j >= 0) { // end streak
18  
        l.add(new Rect(j, 0, i-j, h));
19  
        j = -1;
20  
      }
21  
    }
22  
  if (j >= 0)
23  
    l.add(new Rect(j, 0, w-j, h));
24  
  ret l;
25  
}

Author comment

Began life as a copy of #1005703

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1005709
Snippet name: horizontalAutoSplit [uses column average brightness, for black on white text]
Eternal ID of this version: #1005709/2
Text MD5: d9afad283b938ffa58ddedfeebafba20
Author: stefan
Category: javax / ocr
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-08 00:52:43
Source code size: 675 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 527 / 559
Version history: 1 change(s)
Referenced in: [show references]