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

47
LINES

< > BotCompany Repo | #1015455 // OCRRecognizeAndTeach

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

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

1  
!include once #1015415 // GrabbedImage
2  
3  
sclass OCRRecognizeAndTeach {
4  
  BufferedImage img;
5  
  ImageSurface is; // can pre-set this to reuse image surface
6  
  L<Rect> rects; // use these if not null, otherwise auto-segment
7  
  L<RecognizedText> texts;
8  
  ReliableSingleThread rst = new(r { reRecognize() });
9  
  
10  
  *() {}
11  
  *(ImageSurface *is) { go(is.getImage()); }
12  
  *(BufferedImage img) { go(img); }
13  
  
14  
  void go(BufferedImage img, L<Rect> rects) {
15  
    this.rects = rects;
16  
    go(img);
17  
  }
18  
  
19  
  void go(BufferedImage img) {
20  
    print("Recognizing");
21  
    this.img = img;
22  
    texts = rec();
23  
    is = showImageWithRecognizedTexts(img, is, texts);
24  
    showImageWithRecognizedTexts_makeTeachable2(img, is, texts, simpleRecognizer(), rTrigger(rst));
25  
  }
26  
  
27  
  L<RecognizedText> rec() {
28  
    ret time("OCR", () ->
29  
      rects != null
30  
        ? ocr_recognizeMultiLine_scored(new BWImage(img), simpleRecognizer(), rects)
31  
        : ocr_recognizeMultiLine_scored(img));
32  
  }
33  
  
34  
  void reRecognize {
35  
    print("Re-recognizing...");
36  
    temp tempDisposeWindow(smallLoadingAnim());
37  
    replaceCollection(texts, rec());
38  
    is.repaint();
39  
    print("Done");
40  
  }
41  
  
42  
  void cleanMeUp {
43  
    if (rst != null) rst.cancel();
44  
    disposeWindow(is);
45  
    is = null;
46  
  }
47  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1015455
Snippet name: OCRRecognizeAndTeach
Eternal ID of this version: #1015455/15
Text MD5: 17937b302ea7e92c757bdd5119f831b7
Transpilation MD5: 138177b1d67ecb62d03bcf19557e6557
Author: stefan
Category: javax / ocr / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-12 17:01:33
Source code size: 1283 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 589 / 1172
Version history: 14 change(s)
Referenced in: [show references]