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

62
LINES

< > BotCompany Repo | #1007114 // OCR Test Images [works]

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

Uses 3874K of libraries. Click here for Pure Java version (11913L/83K/299K).

1  
!7
2  
3  
concept TestImage {
4  
  new Ref<PNGFile> pngFile;
5  
  S imageMD5;
6  
  int width, height;
7  
  bool textKnown;
8  
  S text;
9  
}
10  
11  
p-subst {
12  
  SimpleCRUD<TestImage> crud = new SimpleCRUD<TestImage>(TestImage) {
13  
    @Override
14  
    JComponent fieldComponent(TestImage c, S field) {
15  
      if (eq(field, "pngFile"))
16  
        ret new ImageChooser((PNGFile) cget(c, "pngFile"));
17  
      ret super.fieldComponent(c, field);
18  
    }
19  
    
20  
    @Override
21  
    void makeComponents(TestImage c, Map<S, JComponent> map) {
22  
      for (S field : listMinus((L<S>) conceptFieldsInOrder(cc), "width", "height", "imageMD5"))
23  
        map.put(field, fieldComponent(c, field));
24  
    }
25  
    
26  
    @Override
27  
    void saveData(TestImage c, Map<S, JComponent> components) {
28  
      super.saveData(c, components);
29  
      fixEntry(c);
30  
    }
31  
  };
32  
  /*final L<S> fields = concatLists(ll("id"), conceptFieldsInOrder(c));
33  
  crud.renderer = func(TestImage c) {
34  
    Map map = litorderedmap();
35  
    for (S field : fields)
36  
      map.put(field, renderForTable(cget(cc, field)));
37  
    ret map;
38  
  };*/
39  
40  
  crud.show("OCR Test Images");
41  
  bot("OCR Test Images.");
42  
  hideConsole();
43  
}
44  
45  
answer {
46  
  if "add image * with unknown text" {
47  
    PNGFile pngFile = new PNGFile(unstructureBufferedImage($1));
48  
    if (hasConcept(TestImage, imageMD5 := pngFile.md5()))
49  
      ret "Entry already exists";
50  
    long id = fixEntry(cnew(TestImage, +pngFile)).id;
51  
    ret "OK, ID of new entry: " + id;
52  
  }
53  
}
54  
55  
static TestImage fixEntry(TestImage c) {
56  
  BufferedImage img = c.pngFile.has() ? c.pngFile->getImage() : null;
57  
  if (img == null)
58  
    cset(c, imageMD5 := null, width := 0, height := 0);
59  
  else
60  
    cset(c, imageMD5 := md5OfBufferedImage(img), width := img.getWidth(), height := img.getHeight());
61  
  ret c;
62  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1007114
Snippet name: OCR Test Images [works]
Eternal ID of this version: #1007114/24
Text MD5: ff096bbdcc268254776c18e57c7d34fe
Transpilation MD5: 6e06cb7398844c85b9fe9b5b98c1a78c
Author: stefan
Category: javax / ocr
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-05 13:49:18
Source code size: 1783 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 511 / 714
Version history: 23 change(s)
Referenced in: [show references]