!7 static double zoom = 1.5; static volatile BufferedImage img, recognizedImage; static L texts; static ImageSurface is, isWord; static volatile int score; static volatile L posTexts, negTexts; static Set dontPrint; //static int coresToUse() { ret numberOfCores()/2; } p-subst-autorestart { ocr_recognizeMultiLine_scored_maxPixels = 20000; hideConsoleOnFirstFrame(); //mL_setCacheTime(60.0); dontPrint = mechSetCI("Movie Review Cat | Negative/positive words don't print list"); thread "The Loop" { theLoop(); } noMainDone("Cat!"); } svoid theLoop { repeat with sleep 0 { //print("Shooting"); //img = shootScreenHidingConsole(); img = shootScreen2(); //print("Recognizing"); long recTime = sysNow(); texts = ocr_recognizeMultiLine_scored(img); print(filledSimpleRecognizer_cached().cacheStats()); recTime = sysNow()-recTime; time "Post" { L lines = mapMethod('text, texts); MultiSet multiSet = asCIMultiSet(onlyStringsLongerThan(1, words(lines(lines)))); //pnl(multiSetAsMap_popularFirst(multiSet)); Set positiveWords = mechSetCI("Movie Review Cat | Positive words"); Set negativeWords = mechSetCI("Movie Review Cat | Negative words"); Set set = asCISet(keys(multiSet)); final MultiSet plus = multiSetSetIntersection(multiSet, positiveWords); final MultiSet minus = multiSetSetIntersection(multiSet, negativeWords); score = l(plus)-l(minus); posTexts = [RecognizedText r : texts | containsOneOfTheWords(r.text(), setMinusSet(keys(plus), dontPrint))]; negTexts = [RecognizedText r : texts | containsOneOfTheWords(r.text(), setMinusSet(keys(minus), dontPrint))]; L popPlus = mostPopularEntriesFromMultiMap(3, plus); L popMinus = mostPopularEntriesFromMultiMap(3, minus); S text = "Score: " + score; if (score >= 0 && nempty(popPlus)) text += "\n" + joinWithComma(popPlus); if (score <= 0 && nempty(popMinus)) text += "\n" + joinWithComma(popMinus); //infoBox(text); flatInfoBox(recTime + " ms | " + escapeNewLines(text)); S imageID = score == 0 ? #1101256 : score > 0 ? #1101255 : #1101254; recognizedImage = img; } bool first = is == null; is = showImage_hcentered(is, loadImage2_cached(imageID)); if (first) { alwaysOnTopFrame(is); addToWindowWithMargin(is, jfullcenter(isWord = jImageSurface())); enlargeFrameLeftAndBottom(is, 50); isWord.setZoom(2); awtEvery(isWord, 333, f cycleWord); } //packFrame/*InTopRightCorner*/(is); } } svoid cycleWord { if (recognizedImage == null) ret; RecognizedText hilite = null; if (score > 0) hilite = random(posTexts); else if (score < 0) hilite = random(negTexts); if (hilite != null) { final RecognizedText _hilite = hilite; final BufferedImage clip = clipBufferedImage(recognizedImage, hilite.r); isWord.setImage(clip); swing { BufferedImage scaledClip = scaleBufferedImage(clip, zoom); JWindow win = makeWindow(jImageLabel(scaledClip)); Pt p = centerOfRect(_hilite.r); int w = scaledClip.getWidth(), h = scaledClip.getHeight(); win.setBounds(p.x-w/2, p.y-h/2, w, h); win.setAlwaysOnTop(true); win.setVisible(true); disposeWindowAfter(win, 0.5); } } else isWord.setImage(newBufferedImage(1, 1, Color.white)); }