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

65
LINES

< > BotCompany Repo | #1020191 // Circles Finder v1 [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1113K of libraries. Click here for Pure Java version (15329L/80K).

1  
!7
2  
3  
replace Submission with BackgroundPlus<CircleWithColor>.
4  
5  
cm CircleFinder > DynImageSurface {
6  
  int nCircles = 1;
7  
  bool keepGoing;
8  
  new Best<Submission> best;
9  
  
10  
  transient RGBImage original;
11  
  transient Thread recognizerThread;
12  
  transient ImageSurface isCircles;
13  
  transient Submission rendered;
14  
  
15  
  S switchableFields() { ret "nCircles keepGoing"; }
16  
  
17  
  visualize {
18  
    JSpinner spinner = liveValueSpinner(dm_fieldLiveValue('nCircles), 1, 50);
19  
    main.onChange(spinner, r startRecognition );
20  
    ret jvsplit(
21  
      vgrid(super.visualize(), jscroll_centered(isCircles = imageSurface())),
22  
      northAndCenter(
23  
        withSideMargin(rightAlignedLine(
24  
          dm_fieldCheckBox('keepGoing),
25  
          jbutton("Start", r startRecognition),
26  
          jbutton("Stop", r { cancelThread(recognizerThread) }),
27  
          withLabel("Circles:", spinner))),
28  
        dm_printLogComponent()));
29  
  }
30  
31  
  start {
32  
    if (!hasImage()) setImage(whiteImage(50, 50)); // so we can paste...
33  
    onNewImage = r startRecognition;
34  
    doEvery(1.0, r renderCircles);
35  
  }
36  
  
37  
  double scoreImage(RGBImage image) { ret rgbImageSimilarityPercent(image, original); }
38  
  
39  
  void startRecognition enter {
40  
    cancelThread(recognizerThread);
41  
    recognizerThread = startThread(r {
42  
      original = RGBImage(getImage());
43  
      final int w = original.getWidth(), h = original.getHeight();
44  
      print("Starting recognition on " + w + "*" + h + " image");
45  
      best = newBest_sfu();
46  
      //new AIStrategy_RandomWithVariation<Submission> strategy;
47  
      new AIStrategy_Racer_RandomWithVary<Submission> strategy;
48  
      strategy.verbose = true;
49  
      strategy.best = best;
50  
      strategy.submit = func(Submission s) -> double { scoreImage(rgbRenderRenderable(w, h, s)) };
51  
      strategy.random = func -> Submission { randomBackgroundPlusCircles(w, h, nCircles) };
52  
      strategy.vary = func(Submission s) -> Submission { varyBackgroundPlusCircles(s, w, h) };
53  
  
54  
      runStrategy(best, strategy, keepGoing);
55  
      print("Done");
56  
      persistMe();
57  
    });
58  
  }
59  
  
60  
  void renderCircles enter {
61  
    if (original == null || best! == rendered) ret;
62  
    rendered = best!;
63  
    isCircles.setImage(renderRenderable(original.w(), original.h(), rendered));
64  
  }
65  
}

Author comment

Began life as a copy of #1019834

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020191
Snippet name: Circles Finder v1 [Dyn Module]
Eternal ID of this version: #1020191/12
Text MD5: 69189ae8eacc12ab81b894d66faa34fd
Transpilation MD5: a90abb7b52fd4f682b7a2c7d0394ce7c
Author: stefan
Category: javax / image recognition
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-12-21 19:56:34
Source code size: 2289 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 421 / 739
Version history: 11 change(s)
Referenced in: [show references]