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); g.scale(is.zoomX, is.zoomY); Font font = g.getFont().deriveFont(12); g.setFont(font); FontMetrics fm = g.getFontMetrics(); for (RecognizedText r : rects) { is.drawSelectionRect(g, r.r.getRectangle(), Color.blue, blendColor(Color.black, Color.white, r.score())); 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))); }); showImageWithRecognizedTexts_makeTeachable(is, rects, changeExtension(f, ".expected")); ret repaint(is); } svoid showImageWithRecognizedTexts_makeTeachable(ImageSurface is, final L lines, final File outFile) { onImageSurfaceHighlightChange(is, voidfunc(Rect r) { RecognizedText rec = findByField(lines, +r); setToolTip(is, rec == null ? null : str(rec.text)); }); imageSurfacePopupMenuWhenHighlighted_top(is, voidfunc(JPopupMenu menu, final Rect r) { addPopupMenuItem(menu, "OK", r { RecognizedText rec = findByField(lines, +r); appendToTextFile_uniq(outFile, struct(ll(rec.text!, rec.r))); }); addSeparator(menu); }); }