1 | sclass ShootLoop implements Runnable { |
2 | BWImage screen; |
3 | BufferedImage originalScreen; |
4 | int screenWidth, screenHeight; |
5 | ImageSurface isThumb; |
6 | new L<Rect> selections; |
7 | S state = "Shooting & recognizing"; |
8 | float precision = 1f; // how sharply to look at the screen |
9 | bool showThumbnail; |
10 | |
11 | public void run() { |
12 | while licensed { |
13 | sleepSeconds(1); |
14 | once(); |
15 | } |
16 | } |
17 | |
18 | // one step of the loop (shoot, recognize & print) |
19 | void step { once(); } |
20 | void once { |
21 | long time = now(); // todo: switch to sysNow() (will need to change implementations of this class too) |
22 | shoot(); |
23 | recognizeEtc(time); |
24 | } |
25 | |
26 | void recognizeEtc(long time) { |
27 | recognize(); |
28 | printState(time); |
29 | if (showThumbnail) showThumbnail(); |
30 | } |
31 | |
32 | // override me |
33 | void recognize { |
34 | } |
35 | |
36 | // override me |
37 | void printState(long time) { |
38 | done_always(time, state); |
39 | } |
40 | |
41 | void shoot { |
42 | setScreen(shootScreen2()); |
43 | } |
44 | |
45 | void setScreen(BufferedImage img) { |
46 | originalScreen = img; |
47 | screenWidth = originalScreen.getWidth(); |
48 | screenHeight = originalScreen.getHeight(); |
49 | screen = new BWImage(originalScreen); |
50 | } |
51 | |
52 | BWImage screen() { ret screen; } |
53 | |
54 | bool hasImageOnScreen(S imageID) { |
55 | ret findImage(imageID) != null; |
56 | } |
57 | |
58 | // Simple version - searches full screenshot |
59 | Rect findImage(S imageID) { |
60 | ret findImageSingle(screen(), imageID, precision); |
61 | } |
62 | |
63 | Rect findImage(S imageID, float precision) { |
64 | ret findImageSingle(screen(), imageID, precision); |
65 | } |
66 | |
67 | L<Rect> findImageAll(S... imageIDs) { |
68 | ret main.findImagesAll(screen(), asList(imageIDs), precision); |
69 | } |
70 | |
71 | L<Rect> findImageAll(S imageID, float similarity) { |
72 | ret main.findImageAll(screen(), imageID, similarity); |
73 | } |
74 | |
75 | L<Rect> findImageAllOnRow(S imageID, int row) { |
76 | Rect r = new Rect(0, row, screenWidth, 1); |
77 | ret main.findImageAllInPart(screen(), imageID, r, precision); |
78 | } |
79 | |
80 | L<Rect> findImageAllOnColumn(S imageID, int x) { |
81 | Rect r = new Rect(x, 0, 1, screenHeight); |
82 | ret main.findImageAllInPart(screen(), imageID, r, precision); |
83 | } |
84 | |
85 | void showThumbnail() { |
86 | BufferedImage thumb = shrinkScreenshot(originalScreen); |
87 | double factor = thumb.getWidth()/(double) screenWidth; |
88 | new L<Rect> l; |
89 | for (Rect r : selections) |
90 | l.add(scaleRect(r, factor)); |
91 | isThumb = showImageWithSelections(thumb, isThumb, l); |
92 | } |
93 | |
94 | bool topRightCornerIs(S imageID) { |
95 | BWImage pat = loadBWImage_cached(imageID); |
96 | ret bwImageSectionsSimilar(screen(), pat, screenWidth-pat.getWidth(), 0, precision); |
97 | } |
98 | |
99 | float topRightCornerSimilarity(S imageID) { |
100 | BWImage pat = loadBWImage_cached(imageID); |
101 | ret bwImageSectionsSimilarity2(screen(), pat, screenWidth-pat.getWidth(), 0, 0f); |
102 | } |
103 | |
104 | void doSingle(BufferedImage screen) { |
105 | setScreen(screen); |
106 | long time = now(); |
107 | recognizeEtc(time); |
108 | } |
109 | |
110 | void setSelection(FoundImg fi) { |
111 | selections = fi == null ? (L) ll() : ll(fi.r); |
112 | } |
113 | |
114 | void runWithThumbnails() { |
115 | set showThumbnail; |
116 | this.run(); // "this." to soothe standard function adder |
117 | } |
118 | |
119 | RGBImage rgb(Rect r) { |
120 | ret new RGBImage(clipBufferedImage(originalScreen, r)); |
121 | } |
122 | } |
Began life as a copy of #1005831
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005884 |
Snippet name: | ShootLoop class - loop that makes screenshots for recognition |
Eternal ID of this version: | #1005884/1 |
Text MD5: | 3e2d10cb7513e7285c12c8448f7c036b |
Author: | stefan |
Category: | javax / ocr |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-01-05 12:00:25 |
Source code size: | 3265 bytes / 122 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 609 / 1209 |
Referenced in: | [show references] |