Transpiled version (13709L) is out of date.
1 | !7 |
2 | |
3 | cm RecognizeScreen > DynPrintLogAndEnabled { |
4 | switchable int x1; |
5 | switchable int y1; |
6 | switchable int w = screenWidth(); |
7 | switchable int h = screenHeight(); |
8 | switchable double maxFPS = 10; |
9 | switchable int previewWidth = 200; |
10 | switchable double statsEvery = 5; |
11 | |
12 | PersistableThrowable lastProcessingError; |
13 | transient WithTimestamp<OKOrError<BufferedImage>> lastScreen; |
14 | transient new Average screenShotTime; |
15 | transient new Average iiTime; |
16 | transient Timestamp loopStarted; |
17 | transient new RestartableCountdown screenShotCountdown; |
18 | transient BWIntegralImage ii; |
19 | transient ImageSurface imageSurface; |
20 | transient Throwable currentProcessingError; |
21 | transient BufferedImage previewImage; |
22 | |
23 | Rect area() { ret rect(x1, y1, w, h); } |
24 | |
25 | start-thread { |
26 | dm_registerAs_direct gazelleV(); |
27 | dm_watchField enabled(r { if (enabled) dm_reload(); }); |
28 | |
29 | print("Screen bounds: " + allScreenBounds()); |
30 | |
31 | dm_doEvery(min(statsEvery, 10.0), statsEvery, r { if (enabled) printStats(); }); |
32 | |
33 | loopStarted = tsNow(); |
34 | shoot(); |
35 | } |
36 | |
37 | void shoot enter { |
38 | if (!enabled) ret; |
39 | |
40 | long targetTime = sysNow()+iround(1000/maxFPS); |
41 | long time = nanoTime(); |
42 | |
43 | try { |
44 | lastScreen = withTimestamp(okOrError(-> screenshot(area()))); |
45 | screenShotTime.add(nanosToSeconds(nanoTime()-time)); |
46 | if (lastScreen->isOK()) { |
47 | time = nanoTime(); |
48 | ii = BWIntegralImage(lastScreen!!); |
49 | //ii = BWIntegralImage_luminosity(lastScreen!!); |
50 | iiTime.add(nanosToSeconds(nanoTime()-time)); |
51 | |
52 | previewImage = scaledBufferedImageFromBWIntegralImage(ii, previewWidth); |
53 | imageSurface?.setImage(previewImage); |
54 | } |
55 | |
56 | currentProcessingError = null; |
57 | } catch print e { |
58 | setField(lastProcessingError := currentProcessingError = e); |
59 | sleepSeconds(60); // errors in processing are no good |
60 | } |
61 | |
62 | screenShotCountdown.setTargetTime(targetTime, r shoot); |
63 | } |
64 | |
65 | void printStats() { print(stats()); } |
66 | |
67 | S stats() { |
68 | var screen = lastScreen?!; |
69 | ret formatColonProperties_noNulls( |
70 | "Monitored area", area(), |
71 | "Error", screen?.getError(), |
72 | "Last screenshot taken", lastScreen?.timeStamp(), |
73 | "Average time to take a screenshot", screenShotTime, |
74 | "Average time to make integral image", iiTime, |
75 | "Capacity left in first core", percentRatioStrOneDigit(freeInCore()), |
76 | "Total CPU used", percentRatioStrOneDigit((1-freeInCore())/numberOfCores()), |
77 | ); |
78 | } |
79 | |
80 | double freeInCore() { |
81 | ret ratio(toSeconds(screenShotCountdown.totalSleepTime), |
82 | elapsedSeconds(loopStarted)); |
83 | } |
84 | |
85 | visual hsplit(super, jscroll_center(imageSurface = doubleBufferedImageSurface_noAlpha())); |
86 | |
87 | BufferedImage lastScreenImage() { ret getVar(getVar(lastScreen)); } |
88 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033298 |
Snippet name: | Gazelle V (old) |
Eternal ID of this version: | #1033298/32 |
Text MD5: | e26972e97846a45a0e504c89ff7ad75e |
Author: | stefan |
Category: | |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-27 16:10:34 |
Source code size: | 2842 bytes / 88 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 202 / 732 |
Version history: | 31 change(s) |
Referenced in: | [show references] |