sclass ShootLoop implements Runnable { BWImage screen; BufferedImage originalScreen; int screenWidth, screenHeight; ImageSurface isThumb; new L<Rect> selections; S state = "Shooting & recognizing"; float precision = 1f; // how sharply to look at the screen bool showThumbnail; public void run() { while licensed { sleepSeconds(1); once(); } } // one step of the loop (shoot, recognize & print) void step { once(); } void once { long time = now(); // todo: switch to sysNow() (will need to change implementations of this class too) shoot(); recognizeEtc(time); } void recognizeEtc(long time) { recognize(); printState(time); if (showThumbnail) showThumbnail(); } // override me void recognize { } // override me void printState(long time) { done_always(time, state); } void shoot { setScreen(shootScreen2()); } void setScreen(BufferedImage img) { originalScreen = img; screenWidth = originalScreen.getWidth(); screenHeight = originalScreen.getHeight(); screen = new BWImage(originalScreen); } BWImage screen() { ret screen; } bool hasImageOnScreen(S imageID) { ret findImage(imageID) != null; } // Simple version - searches full screenshot Rect findImage(S imageID) { ret findImageSingle(screen(), imageID, precision); } Rect findImage(S imageID, float precision) { ret findImageSingle(screen(), imageID, precision); } L<Rect> findImageAll(S... imageIDs) { ret main.findImagesAll(screen(), asList(imageIDs), precision); } L<Rect> findImageAll(S imageID, float similarity) { ret main.findImageAll(screen(), imageID, similarity); } L<Rect> findImageAllOnRow(S imageID, int row) { Rect r = new Rect(0, row, screenWidth, 1); ret main.findImageAllInPart(screen(), imageID, r, precision); } L<Rect> findImageAllOnColumn(S imageID, int x) { Rect r = new Rect(x, 0, 1, screenHeight); ret main.findImageAllInPart(screen(), imageID, r, precision); } void showThumbnail() { BufferedImage thumb = shrinkScreenshot(originalScreen); double factor = thumb.getWidth()/(double) screenWidth; new L<Rect> l; for (Rect r : selections) l.add(scaleRect(r, factor)); isThumb = showImageWithSelections(thumb, isThumb, l); } bool topRightCornerIs(S imageID) { BWImage pat = loadBWImage_cached(imageID); ret bwImageSectionsSimilar(screen(), pat, screenWidth-pat.getWidth(), 0, precision); } float topRightCornerSimilarity(S imageID) { BWImage pat = loadBWImage_cached(imageID); ret bwImageSectionsSimilarity2(screen(), pat, screenWidth-pat.getWidth(), 0, 0f); } void doSingle(BufferedImage screen) { setScreen(screen); long time = now(); recognizeEtc(time); } void setSelection(FoundImg fi) { selections = fi == null ? (L) ll() : ll(fi.r); } void runWithThumbnails() { set showThumbnail; this.run(); // "this." to soothe standard function adder } RGBImage rgb(Rect r) { ret new RGBImage(clipBufferedImage(originalScreen, r)); } }
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: | 608 / 1207 |
Referenced in: | [show references] |