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

37
LINES

< > BotCompany Repo | #1006339 // ocr_recognizeTextClips

JavaX fragment (include)

static int ocr_recognizeTextClips_spaceDist = 7;

static L<S> ocr_recognizeTextClips(BWImage bw, L<Rect> clips) {
  SimpleRecognizer sr = filledSimpleRecognizer_cached();
  final L<Rect> rects = autoSegment(bw);
  new L<S> lines;
  for (Rect clip:  clips) {
    S s = diamond();
    pcall {
      BWImage clipImg = autoCroppedBWImage(bw.clip(clip));
      new L<Rect> gclips; // glyph clips
      L<S> groups = sr.recognizeGrouped(clipImg, gclips);
      int n = l(groups);
      if (l(gclips) != n)
        print("huh? " + n + "/" + l(gclips));
      else {
        //print("Finding spaces. " + n + " characters");
        for (int i = 0; i < l(groups)-1; i++) {
          Rect a = gclips.get(i);
          Rect b = gclips.get(i+1);
          if (a != null && b != null) {
            int dist = b.x-a.x2();
            //print("Space dist between " + groups.get(i) + " and " + groups.get(i+1) + ": " + dist);
            if (dist >= ocr_recognizeTextClips_spaceDist) {
              groups.add(i+1, " ");
              gclips.add(i+1, null);
              ++i;
            }
          }
        }
      }
      s = ocr_joinGroups(groups);
    }
    lines.add(s);
  }
  ret lines;
}

Author comment

Began life as a copy of #1006333

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1006339
Snippet name: ocr_recognizeTextClips
Eternal ID of this version: #1006339/1
Text MD5: bd6dcc1999e451f26a4ee3521626e89a
Author: stefan
Category: javax / ocr
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-29 00:55:35
Source code size: 1219 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 457 / 488
Referenced in: [show references]