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

45
LINES

< > BotCompany Repo | #1015395 // ocr_teachPhraseForm

JavaX fragment (include) [tags: use-pretranspiled]

Uses 108K of libraries. Click here for Pure Java version (11204L/81K).

1  
!include once #1015415 // GrabbedImage
2  
3  
svoid ocr_teachPhraseForm(final GrabbedImage gi, final SimpleRecognizer sr, final VF1<S> onTaught) {
4  
  analyzeGrabbedImage(gi, sr);
5  
6  
  // make form
7  
  final JTextField tf = jTypeWriterTextField(ocr_joinAsGrouped(gi.groupedRecognition));
8  
  final JCheckBox grouped = jCheckBox("grouped (" + ocrCharGroupingHelpText() + ")", true);
9  
  final JButton btnSubmit = jbutton("Submit", r {
10  
    S s = trim(tf.getText());
11  
    bool group = isChecked(grouped);
12  
    L<Rect> rects = gi.rects;
13  
    if (group) { rects = ocr_groupRects(rects, s); s = ocr_unmerge(s); }
14  
    saveScreenClip(gi.image);
15  
    L<S> characterMD5s = md5OfBWImageParts(gi.image, rects);
16  
    
17  
    if (sr.fullSearchMap != null)
18  
      for i over rects:
19  
        sr.fullSearchMap.put(gi.image.clip(rects.get(i)), characterMD5s.get(i));
20  
      
21  
    S line = "The images " + quote(join(" ", characterMD5s)) + " are the " + (group ? "grouped " : "") + "characters " + quote(s) + ".";
22  
    print(">> " + line);
23  
    S imageMD5 = ocrMD5OfBWImage(gi.image);
24  
    logQuoted(glyphTeachLog(), "[" + localDateWithSeconds() + "] Image " + imageMD5 + ": " + line);
25  
    saveTextFile(newFile(screenClipsDir(), imageMD5 + ".line"), line);
26  
27  
    sr.load(line);
28  
    disposePossiblyInternalFrame(tf);
29  
    pcallF(onTaught, s);
30  
  });
31  
  onUpdateAndNow(ll(tf, grouped), r {
32  
    S s = trim(tf.getText());
33  
    btnSubmit.setEnabled((isChecked(grouped) ? ocr_glyphCount(s) : l(dropSpaces(s))) == l(gi.characters));
34  
  });
35  
  
36  
  // show form
37  
  growFrameSouth(50, showFormTitled("Teach",
38  
    "Image:" , jscroll_minHeight(75, zoomedImageSurface(2, gi.image.getBufferedImage())),
39  
    "Split:" , jscroll_minHeight(75, zoomedImageSurface(2, gi.visualizedSplit.getBufferedImage())),
40  
    "Meaning:", tf,
41  
    "", grouped,
42  
    "", btnSubmit));
43  
    
44  
  selectAllLater(tf, 100);
45  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1015395
Snippet name: ocr_teachPhraseForm
Eternal ID of this version: #1015395/11
Text MD5: 8de91f3b7a049e4354cbd4287c5b4567
Transpilation MD5: 1e18005ffc26fb50a46bc0dc83d66ad8
Author: stefan
Category: javax / imaging / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-12 17:05:59
Source code size: 1865 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 282 / 363
Version history: 10 change(s)
Referenced in: [show references]