Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

82
LINES

< > BotCompany Repo | #1015468 // Movie Review Cat [shortened]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 3981K of libraries. Click here for Pure Java version (15153L/115K).

1  
!7
2  
3  
static double zoom = 1.5;
4  
static volatile BufferedImage img, recognizedImage;
5  
static L<RecognizedText> texts;
6  
static ImageSurface is, isWord;
7  
static volatile int score;
8  
static volatile L<RecognizedText> posTexts, negTexts;
9  
static Set<S> dontPrint;
10  
sbool scoreBox;
11  
static int coresToUse = 1;
12  
13  
p-subst-autorestart {
14  
  run(#1015409);
15  
  ocr_recognizeMultiLine_scored_maxPixels = 20000;
16  
  hideConsoleOnFirstFrame();
17  
  dontPrint = mechSetCI("Movie Review Cat | Negative/positive words don't print list");
18  
  thread "The Loop" { theLoop(); }
19  
  noMainDone("Cat!");
20  
}
21  
  
22  
svoid theLoop {
23  
  repeat with sleep 0 {
24  
    temp tempSetCoresToUse(coresToUse);
25  
    img = shootScreen2();
26  
    long recTime = sysNow();
27  
    assertEquals("Cores to use", coresToUse, coresToUse_fixed());
28  
    texts = ocr_recognizeMultiLine_scored(img);
29  
    print(filledSimpleRecognizer_cached().cacheStats());
30  
    recTime = sysNow()-recTime;
31  
      
32  
    time "Post" {
33  
      MultiSet<S> multiSet = asCIMultiSet(words(lines(mapMethod('text, texts))));
34  
      Set<S> positiveWords = mechSetCI("Movie Review Cat | Positive words");
35  
      Set<S> negativeWords = mechSetCI("Movie Review Cat | Negative words");
36  
      final MultiSet<S> plus = multiSetSetIntersection(multiSet, positiveWords);
37  
      final MultiSet<S> minus = multiSetSetIntersection(multiSet, negativeWords);
38  
      score = l(plus)-l(minus);
39  
      
40  
      posTexts = [RecognizedText r : texts | containsOneOfTheWords(r.text(), setMinusSet(keys(plus), dontPrint))];
41  
      negTexts = [RecognizedText r : texts | containsOneOfTheWords(r.text(), setMinusSet(keys(minus), dontPrint))];
42  
        
43  
      L<S> popPlus = mostPopularEntriesFromMultiMap(3, plus);
44  
      L<S> popMinus = mostPopularEntriesFromMultiMap(3, minus);
45  
      
46  
      S text = "Score: " + score;
47  
      if (scoreBox) {
48  
        if (score >= 0 && nempty(popPlus)) text += "\n" + joinWithComma(popPlus);
49  
        if (score <= 0 && nempty(popMinus)) text += "\n" + joinWithComma(popMinus);
50  
        flatInfoBox(recTime + " ms | " + escapeNewLines(text));
51  
      }
52  
      S imageID = minusZeroPlus(score, #1101254, #1101256, #1101255);
53  
      recognizedImage = img;
54  
    }
55  
56  
    bool first = is == null;
57  
    is = showImage_hcentered(is, "Movie Review Cat!", loadImage2_cached(imageID));
58  
    if (first) {
59  
      setDoubleBuffered(is, true);
60  
      frameTitlePopupMenu(is, voidfunc(JPopupMenu menu) {
61  
        menu.add(boolFieldMenuItem(mc(), 'scoreBox));
62  
        menu.add(intFieldMenuItem(mc(), 'coresToUse));
63  
      });
64  
      alwaysOnTopFrame(is);
65  
      addToWindowWithMargin(is, jfullcenter(isWord = jImageSurface()));
66  
      enlargeFrameLeftAndBottom(is, 50);
67  
      isWord.setZoom(2);
68  
      awtEvery(isWord, 333, f cycleWord);
69  
    }
70  
  }
71  
}
72  
73  
svoid cycleWord {
74  
  if (recognizedImage == null) ret;
75  
  RecognizedText hilite = random(score > 0 ? posTexts : score < 0 ? negTexts : null);
76  
  if (hilite != null) {
77  
    BufferedImage clip = clipBufferedImage(recognizedImage, hilite.r);
78  
    isWord.setImage(clip);
79  
    showZoomedScreenClipInPlace(hilite.r, clip, zoom, 0.5);
80  
  } else
81  
    isWord.setImage(newBufferedImage(1, 1, Color.white));
82  
}

Author comment

Began life as a copy of #1015422

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, vpdwwinrgdga

No comments. add comment

Snippet ID: #1015468
Snippet name: Movie Review Cat [shortened]
Eternal ID of this version: #1015468/17
Text MD5: 4fa2d740b3547863d0fefc2f4b63c487
Transpilation MD5: 615316c4a7174fb0506621962237444b
Author: stefan
Category: javax / ocr
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-31 03:35:39
Source code size: 3172 bytes / 82 lines
Pitched / IR pitched: No / No
Views / Downloads: 371 / 888
Version history: 16 change(s)
Referenced in: [show references]