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

78
LINES

< > BotCompany Repo | #1005852 // Learn to read [dev.]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (4402L/29K/99K).

!752

please include function img_upperWidthToLowerWidth.
please include function img_averageWidthDividedByHeight.
please include function img_centralPixelSet.
please include function img_leftishness.

sS font = "#1004569";
static float size = 40f;

static BWImage render(S text) {
  ret autoCroppedBWImage(renderText(font, size, text));
}

p {
  BWImage zero = autoCroppedBWImage(renderText(font, size, "0"));
  BWImage one = autoCroppedBWImage(renderText(font, size, "1"));
  showBWImage(zero);
  showBWImage(one);
  Map<S, L<Range>> ranges = new TreeMap;
  
  for (size = 10f; size <= 60f; size++)
    analyze(ll(render("0"), render("1")), ranges, "upperWidthToLowerWidth averageWidthDividedByHeight centralPixelSet leftishness");
    
  //printStruct(ranges);
  
  for (S key : keys(ranges)) {
    L<Range> l = ranges.get(key);
    if (rangesOverlap(l))
      print("bad: " + key);
    else
      print("good! " + key);
  }
}

svoid analyze(L<BWImage> images, Map<S, L<Range>> ranges, S functions) {
  for (S f : splitAtSpace(functions)) {
    L<Range> l = ranges.get(f);
    if (l == null)
      ranges.put(f, l = new L);
    for i over images: {
      BWImage img = images.get(i);
      float val = 0f;
      try {
        val = toFloat(call(mc(), "img_" + f, img));
      } catch e { printShortException(e); }
      listSet(l, i, addToRange(get(l, i), val), null);
    }
  }
}

// can overwrite original object
static Range addToRange(Range r, float val) {
  if (r == null)
    ret new Range(val);
  if (r.min > r.max)
    r.min = r.max = val;
  else {
    if (val < r.min) r.min = val;
    if (val > r.max) r.max = val;
  }
  ret r;
}

static bool rangesOverlap(Range a, Range b) {
  ret intersectRanges(a, b) != null;
}

static Range intersectRanges(Range a, Range b) {
  float min = max(a.min, b.min);
  float max = min(a.max, b.max);
  ret min <= max ? new Range(min, max) : null;
}

static bool rangesOverlap(L<Range> l) {
  assertTrue(l(l) == 2);
  ret rangesOverlap(first(l), last(l));
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1005852
Snippet name: Learn to read [dev.]
Eternal ID of this version: #1005852/1
Text MD5: 3b3b55030f527a5ee9d0de0666429f74
Transpilation MD5: 39d1f2e707dd75a300ddca8f33724ae1
Author: stefan
Category: javax / ocr
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-11 16:52:32
Source code size: 2078 bytes / 78 lines
Pitched / IR pitched: No / No
Views / Downloads: 453 / 559
Referenced in: [show references]