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

81
LINES

< > BotCompany Repo | #1005726 // Split text into characters with table of characters and MD5s

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

Libraryless. Click here for Pure Java version (9242L/64K/215K).

!752

static BWImage img;
static ImageSurface is2;
static float threshold = 0.99f; // for horizontalAutoSplit
static JTable table;
static JTextField tfText;
static L<Rect> split;
static L<BWImage> characters;

concepts.

concept Result {
  BWImage inputImage;
  float horizontalSplitThreshold;
  L<BWImage> characters;
  //Bool splitOK;
  S text;
}

p {
  concepts();
  dbBot();
  if (img == null)
    img = getBWImageFromClipboard();
  if (img == null)
    img = loadBWImage("#1005702");
  update();
}

svoid update() {
  RGBImage vis = visualize().toRGB();
  if (is2 == null) {
    is2 = showZoomedImage(vis);
    addToWindowAndPack(is2, liveSliderZeroToOne(threshold/10000f*9999f, voidfunc(float x) {
      threshold = x*10000f/9999f;
      update();
    }));
  } else
    is2.setImage(vis);
    
  // show table
  
  new L<L> data;
  characters = new L;
  for (Rect r : split) {
    BWImage clip = img.clip(r);
    characters.add(clip);
    data.add(ll(clip.getBufferedImage(), md5OfBWImage(clip)));
  }
  bool first = table == null;
  table = showTableWithImages("Characters + MD5", splitAtSpace("Character MD5"), data, table);
  if (first) {
    table.setRowHeight(25);
    addToWindow(table, centerAndEast(
      withLabel("Text:", tfText = new JTextField),
      jbutton("Save result", "saveResult")));
    onEnter(tfText, "saveResult");
  }
}

svoid saveResult {
  S text = tfText.getText();
  /*if (l(text) != l(characters))
    messageBox("Character count doesn't match! " + l(text) + " vs " + l(characters));
  else*/ {
    Result result = cnew(Result,
      inputImage := img, horizontalSplitThreshold := threshold,
      +characters, +text);
    messageBox("Result saved! id: " + result.id);
  }
}

static BWImage visualize() {
  BWImage im = new BWImage(img);
  for (Rect r : split = horizontalAutoSplit(img, threshold)) {
    r = autoCropOfBWImage(img, r);
    darkenBWImagePart(im, r);
  }
  ret im;
}

Author comment

Began life as a copy of #1005711

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1005726
Snippet name: Split text into characters with table of characters and MD5s
Eternal ID of this version: #1005726/1
Text MD5: 127c68bd71dfc2fcd2a27e256b604f78
Transpilation MD5: 566160e7cde37c0d4ec57af031d98435
Author: stefan
Category: javax / ocr
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-18 00:18:28
Source code size: 1998 bytes / 81 lines
Pitched / IR pitched: No / No
Views / Downloads: 528 / 1118
Referenced in: [show references]