Uses 108K of libraries. Click here for Pure Java version (15380L/113K).
1 | abstract sclass DynVisualBot > DynPrintLogAndEnabled { |
2 | transient Map<S, BWImage> protos = syncCIMap(); |
3 | ISegmenter segmenter; |
4 | transient autoDispose new ScreenShooter shooter; |
5 | transient bool useShooter = true; |
6 | transient ReliableSingleThread rstSegment = dm_rst(module(), r segment); |
7 | transient ReliableSingleThread rstAOA = dm_rst(module(), r aoa); |
8 | transient ImageInfo info, latestWithAOA; |
9 | transient ImageSurface isThings; |
10 | transient double requiredImageSimilarity = 95; |
11 | transient L afterSegmenting = ll(rstAOA); // L<Runnable|voidfunc(ImageInfo)> |
12 | |
13 | sclass Segment extends BWImageAndRect { *() {} *(Rect r) { super(r); } } |
14 | sclass ImageInfo extends ImageWithProtos<Segment> {} |
15 | |
16 | visualize { |
17 | JComponent sup = super.visualize(); |
18 | containerAddFirst(buttons, jbutton("Show segments", rThread showSegments)); |
19 | ret jvsplit( |
20 | jCenteredSection("Things found on screen", jscroll_center(isThings = jDoubleBufferedImageSurface())), |
21 | sup); |
22 | } |
23 | |
24 | start-thread { |
25 | dm_requireMouseMover(); |
26 | dm_watchFieldAndNow enabled(r { set(shooter, enabled := useShooter && enabled) }); |
27 | if (empty(protos)) |
28 | makeProtos(); |
29 | print("Have " + n2(protos, "proto")); |
30 | if (segmenter == null) |
31 | setField(segmenter := makeSegmenter()); |
32 | print("Have segmenter: " + segmenter); |
33 | |
34 | shooter.onNewImage.add(rstSegment); |
35 | shooter.start(enter := f<AutoCloseable> enter); |
36 | started(); |
37 | } |
38 | |
39 | /* override me */ void started {} |
40 | /* override me */ void makeProtos {} |
41 | /* override me */ ISegmenter makeSegmenter() { null; } |
42 | |
43 | void segment { |
44 | segment(shooter.latestImage); |
45 | } |
46 | |
47 | ImageInfo segment(BufferedImage img) { |
48 | if (!enabled || img == null || segmenter == null) null; // man weiß ja nie... |
49 | this.info = (ImageInfo) imageWithProtos_segment(segmenter, img, |
50 | iwpClass := ImageInfo.class, segmentClass := Segment.class); |
51 | pcallFAll(afterSegmenting, info); |
52 | ret info; |
53 | } |
54 | |
55 | void aoa { |
56 | ImageInfo info = this.info, ret if null; |
57 | imageWithProtos_doAllOnAll(info, protos, minScore := requiredImageSimilarity, +isThings); |
58 | latestWithAOA = info; |
59 | } |
60 | |
61 | void protoTexts(S... texts) { |
62 | putAll(protos, mapValues loadBWImage(imageSnippetIDsForNames(llQuoted(texts)))); |
63 | } |
64 | |
65 | void showSegments() { |
66 | ImageInfo info = this.info, ret if null; |
67 | showMergedBWImagesVertically(firstToUpper(nSegments(info.segments)), collect image(info.segments)); |
68 | } |
69 | } |
Began life as a copy of #1025026
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1025035 |
Snippet name: | DynVisualBot [continuous screenshots, searches for protos] |
Eternal ID of this version: | #1025035/13 |
Text MD5: | 4e13b7bd7f8d58d3ea297bb30647969a |
Transpilation MD5: | 06d51d84d0cd562969399a31781e8d6c |
Author: | stefan |
Category: | javax / visual bots |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-09-08 17:27:14 |
Source code size: | 2493 bytes / 69 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 270 / 722 |
Version history: | 12 change(s) |
Referenced in: | [show references] |