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

43
LINES

< > BotCompany Repo | #1015302 // showImageWithRecognizedTexts

JavaX fragment (include)

1  
please include function showImageWithSelections.
2  
3  
static float showImageWithSelections_darkening = 0.75f;
4  
5  
static ImageSurface showImageWithRecognizedTexts(BufferedImage img, ImageSurface _is, final L<RecognizedText> rects) {
6  
  final ImageSurface is = showImage(img, _is);
7  
  is.specialPurposed = true;
8  
  final new Var<Rect> highlighted;
9  
  showImageWithSelections_highlighted = highlighted;
10  
  is.overlay = voidfunc(Graphics2D g) {
11  
    fillRect(g, 0, 0, is.getWidth(), is.getHeight(), colorWithAlpha(Color.black, showImageWithSelections_darkening));
12  
    antiAliasOn(g);
13  
    temp tempGraphicsTransform(g);
14  
    g.scale(is.zoomX, is.zoomY);
15  
    Font font = g.getFont().deriveFont(12);
16  
    g.setFont(font);
17  
    FontMetrics fm = g.getFontMetrics();
18  
    for (RecognizedText r : cloneList(rects)) {
19  
      is.drawSelectionRect(g, r.r.getRectangle(), Color.blue, blendColor(Color.black, Color.white, /*ocr_minScoreAdjust*/(r.score())), 1, 1);
20  
      
21  
      S text = r.text!;
22  
      if (nempty(text) && neq(text, ocr_unknownCharacterPlaceholder())) {
23  
        Pt p = centerTextInRect(fm, r.text!, r.r);
24  
        // Pt p = pt(r.r.x+2, r.r.y+2);
25  
        drawTextWithOutline(g, r.text!, p.x, p.y, Color.white, Color.black);
26  
      }
27  
    }
28  
    if (highlighted.has())
29  
      fillRect(g, scaleRect(highlighted!, is.getZoomX(), is.getZoomY()), new Color(0, 0, 0, 0x30)); // semi-transparent black
30  
  };
31  
  imageSurfaceOnMouseMove(is, voidfunc(Pt p) {
32  
    /*repaintIf(is,*/ setVarIfNeq(highlighted, smallestRectContaining(collect(rects, 'r), p))/*)*/;
33  
  });
34  
  
35  
  imageSurfacePopupMenuOnSelection_top(is, voidfunc(JPopupMenu menu, final Rect selection) {
36  
    addMenuItem(menu, "Export selected texts", r {
37  
      showText("Selected recognized texts",
38  
        lines(allToStruct(recognizedTextsFullyContainedIn(rects, selection))))
39  
    });
40  
  });
41  
  
42  
  ret repaint(is);
43  
}

Author comment

Began life as a copy of #1005839

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1015302
Snippet name: showImageWithRecognizedTexts
Eternal ID of this version: #1015302/30
Text MD5: 8f5aa7abab77e22dbf32277e27389b05
Author: stefan
Category: javax / imaging / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-07 20:05:40
Source code size: 1879 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 443 / 477
Version history: 29 change(s)
Referenced in: [show references]