Download Jar. Uses 3874K of libraries. Click here for Pure Java version (11768L/87K).
!7 static double zoom = 1.5; static volatile BufferedImage img, recognizedImage; static L<RecognizedText> texts; static ImageSurface is, isWord; static volatile int score; static volatile L<RecognizedText> posTexts, negTexts; static Set<S> 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<S> lines = mapMethod('text, texts); MultiSet<S> multiSet = asCIMultiSet(onlyStringsLongerThan(1, words(lines(lines)))); //pnl(multiSetAsMap_popularFirst(multiSet)); Set<S> positiveWords = mechSetCI("Movie Review Cat | Positive words"); Set<S> negativeWords = mechSetCI("Movie Review Cat | Negative words"); Set<S> set = asCISet(keys(multiSet)); final MultiSet<S> plus = multiSetSetIntersection(multiSet, positiveWords); final MultiSet<S> 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<S> popPlus = mostPopularEntriesFromMultiMap(3, plus); L<S> 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)); }
Began life as a copy of #1015266
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, tvejysmllsmz
No comments. add comment
Snippet ID: | #1015422 |
Snippet name: | Movie Review Cat! |
Eternal ID of this version: | #1015422/64 |
Text MD5: | 42cc758a2a783f9df13ae39967c0f4fe |
Transpilation MD5: | 21b870cf3eacc6ccc40209a10e7e154c |
Author: | stefan |
Category: | javax / ocr |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | Yes |
Created/modified: | 2018-06-16 13:31:19 |
Source code size: | 3604 bytes / 100 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 631 / 1880 |
Version history: | 63 change(s) |
Referenced in: | [show references] |