please include function showImageWithSelections. static float showImageWithSelections_darkening = 0.75f; static ImageSurface showImageWithRecognizedTexts(BufferedImage img, ImageSurface _is, final L rects) { final ImageSurface is = showImage(img, _is); is.specialPurposed = true; final new Var highlighted; showImageWithSelections_highlighted = highlighted; is.overlay = voidfunc(Graphics2D g) { fillRect(g, 0, 0, is.getWidth(), is.getHeight(), colorWithAlpha(Color.black, showImageWithSelections_darkening)); antiAliasOn(g); temp tempGraphicsTransform(g); g.scale(is.zoomX, is.zoomY); Font font = g.getFont().deriveFont(12); g.setFont(font); FontMetrics fm = g.getFontMetrics(); for (RecognizedText r : cloneList(rects)) { is.drawSelectionRect(g, r.r.getRectangle(), Color.blue, blendColor(Color.black, Color.white, /*ocr_minScoreAdjust*/(r.score())), 1, 1); S text = r.text!; if (nempty(text) && neq(text, ocr_unknownCharacterPlaceholder())) { Pt p = centerTextInRect(fm, r.text!, r.r); // Pt p = pt(r.r.x+2, r.r.y+2); drawTextWithOutline(g, r.text!, p.x, p.y, Color.white, Color.black); } } if (highlighted.has()) fillRect(g, scaleRect(highlighted!, is.getZoomX(), is.getZoomY()), new Color(0, 0, 0, 0x30)); // semi-transparent black }; imageSurfaceOnMouseMove(is, voidfunc(Pt p) { /*repaintIf(is,*/ setVarIfNeq(highlighted, smallestRectContaining(collect(rects, 'r), p))/*)*/; }); imageSurfacePopupMenuOnSelection_top(is, voidfunc(JPopupMenu menu, final Rect selection) { addMenuItem(menu, "Export selected texts", r { showText("Selected recognized texts", lines(allToStruct(recognizedTextsFullyContainedIn(rects, selection)))) }); }); ret repaint(is); }