!include once #1015415 // GrabbedImage sclass OCRRecognizeAndTeach { BufferedImage img; ImageSurface is; // can pre-set this to reuse image surface L rects; // use these if not null, otherwise auto-segment L texts; ReliableSingleThread rst = new(r { reRecognize() }); *() {} *(ImageSurface *is) { go(is.getImage()); } *(BufferedImage img) { go(img); } void go(BufferedImage img, L rects) { this.rects = rects; go(img); } void go(BufferedImage img) { print("Recognizing"); this.img = img; texts = rec(); is = showImageWithRecognizedTexts(img, is, texts); showImageWithRecognizedTexts_makeTeachable2(img, is, texts, simpleRecognizer(), rTrigger(rst)); } L rec() { ret time("OCR", () -> rects != null ? ocr_recognizeMultiLine_scored(new BWImage(img), simpleRecognizer(), rects) : ocr_recognizeMultiLine_scored(img)); } void reRecognize { print("Re-recognizing..."); temp tempDisposeWindow(smallLoadingAnim()); replaceCollection(texts, rec()); is.repaint(); print("Done"); } void cleanMeUp { if (rst != null) rst.cancel(); disposeWindow(is); is = null; } }