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).

!7

replace Submission with BackgroundPlus<CircleWithColor>.

cm CircleFinder > DynImageSurface {
  int nCircles = 1;
  bool keepGoing;
  new Best<Submission> best;
  
  transient RGBImage original;
  transient Thread recognizerThread;
  transient ImageSurface isCircles;
  transient Submission rendered;
  
  S switchableFields() { ret "nCircles keepGoing"; }
  
  visualize {
    JSpinner spinner = liveValueSpinner(dm_fieldLiveValue('nCircles), 1, 50);
    main.onChange(spinner, r startRecognition );
    ret jvsplit(
      vgrid(super.visualize(), jscroll_centered(isCircles = imageSurface())),
      northAndCenter(
        withSideMargin(rightAlignedLine(
          dm_fieldCheckBox('keepGoing),
          jbutton("Start", r startRecognition),
          jbutton("Stop", r { cancelThread(recognizerThread) }),
          withLabel("Circles:", spinner))),
        dm_printLogComponent()));
  }

  start {
    if (!hasImage()) setImage(whiteImage(50, 50)); // so we can paste...
    onNewImage = r startRecognition;
    doEvery(1.0, r renderCircles);
  }
  
  double scoreImage(RGBImage image) { ret rgbImageSimilarityPercent(image, original); }
  
  void startRecognition enter {
    cancelThread(recognizerThread);
    recognizerThread = startThread(r {
      original = RGBImage(getImage());
      final int w = original.getWidth(), h = original.getHeight();
      print("Starting recognition on " + w + "*" + h + " image");
      best = newBest_sfu();
      //new AIStrategy_RandomWithVariation<Submission> strategy;
      new AIStrategy_Racer_RandomWithVary<Submission> strategy;
      strategy.verbose = true;
      strategy.best = best;
      strategy.submit = func(Submission s) -> double { scoreImage(rgbRenderRenderable(w, h, s)) };
      strategy.random = func -> Submission { randomBackgroundPlusCircles(w, h, nCircles) };
      strategy.vary = func(Submission s) -> Submission { varyBackgroundPlusCircles(s, w, h) };
  
      runStrategy(best, strategy, keepGoing);
      print("Done");
      persistMe();
    });
  }
  
  void renderCircles enter {
    if (original == null || best! == rendered) ret;
    rendered = best!;
    isCircles.setImage(renderRenderable(original.w(), original.h(), rendered));
  }
}

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: 419 / 737
Version history: 11 change(s)
Referenced in: [show references]