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

71
LINES

< > BotCompany Repo | #1027213 // Image Recognition for Vector Spike (backup 1)

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

Uses 911K of libraries. Click here for Pure Java version (5731L/32K).

!7

// uses only one prototype image
// goes through different granularities at once

cmodule ImageRecogSpike {
  switchable S prototypeImageID = #1102884;
  switchable S inputImageID = #1102883;

  // how big do we think the prototype is in the whole image
  // (percentage by height)
  transient double assumedPrototypeHeightPercentage = 70;
  
  transient L<Int> widths = ll(32, 64, 128);
  transient new L<IBWIntegralImage> integralImages;
  transient BWIntegralImage baseImage;
  transient JTabbedPane tabs = jTabbedPane();
  transient BWImage prototypeImage;
  transient new L<OneLevel> levels; // recognizers for each granularity

  class OneLevel extends SteppableAndBest<Rect> {
    IBWIntegralImage ii; // scaled integral image
    BWImage image;       // scaled image
    BWImage prototype;   // scaled prototype
    float minSimilarity = 0.5f;
    ImageSurface is;

    *(IBWIntegralImage *ii) {
      image = iBWIntegralImageToBWImage(ii);
      // get assumed height of prototype in scaled-down image
      int ph = iround(ii.getHeight()*assumedPrototypeHeightPercentage/100.0);
      // resize prototype
      prototype = bwResizeToHeightSmooth(prototypeImage, ph);
      addTab(tabs, "proto " + ii.getWidth(),
        jFullCenterScroll(jPixelatedZoomedImageSurface(4.0, prototype)));
    }
    
    public bool step() {
      FoundImg fi = bwImageSearch_best(image, prototype, minSimilarity);
      print("Search result: " + fi);
      if (fi != null) {
        best.put(fi.r, fi.sim);
        setImageSurfaceSelection(is, best!);
      }
      false; // done
    }
  }
  
  start-thread {
    if (baseImage == null)
      baseImage = BWIntegralImage(loadImage2(inputImageID));
    if (prototypeImage == null)
      prototypeImage = loadBWImage(prototypeImageID);
    for (int w : widths) {
      IBWIntegralImage ii = scaledIBWIntegralImage(baseImage, w);
      integralImages.add(ii);
      ImageSurface is = jPixelatedZoomedImageSurface(
        doubleRatio(baseImage.getWidth(), w), iBWIntegralImageToBWImage(ii));
      addTab(tabs, "w=" + w, jFullCenterScroll(is));
      levels.add(setAll(new OneLevel(ii), +is));
    }
    addTab(tabs, "Prototype", jFullCenterScroll(jPixelatedZoomedImageSurface(4, prototypeImage)));

    time "Process" {
      for (OneLevel lvl : levels)
        lvl.step();
    }
  }

  visual tabs;
}

Author comment

Began life as a copy of #1027204

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

-
Snippet ID: #1027213
Snippet name: Image Recognition for Vector Spike (backup 1)
Eternal ID of this version: #1027213/1
Text MD5: e61955f1268515d9e9a64167297bcea9
Transpilation MD5: 4b041530a7e0cd114cfa4230b7db3962
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: 2020-02-26 12:17:13
Source code size: 2415 bytes / 71 lines
Pitched / IR pitched: No / No
Views / Downloads: 274 / 371
Referenced in: