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

74
LINES

< > BotCompany Repo | #1027288 // Vector Live Recognition Spike ["finds" the wrong spots?]

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

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

!7

cmodule VectorLiveRecogSpike1 > DynImageSurfaceAndEnabled {
  transient ReliableSingleThread rstRecog = dm_rst(this, r recognize);
  
  start {
    rstRecog.trigger();
    dm_vmBus_onMessage haveVectorImage((mod, _img) -> rstRecog.trigger());
  }
  
  void recognize {
    if (!enabled) ret;
    BufferedImage inputImage = dm_getLatestVectorImage();
    CheesyRecognizer rec = new(inputImage);
    CheesyRecognizer.Prototype proto = rec.addPrototype(loadBWImage(#1102893));
    int w = rec.getWidth(); // input image width
    int w1 = 16; // coarse resolution to scan
    int w2 = 128; // fine resolution to scan
    print(+w);
    L<Int> assumedProtoSizes = sqrt2progression_int_dropFirst(5, w);
    print(+assumedProtoSizes);
    time "Recog" {
      // Look for center-of-object candidates in coarse resolution
    
      new LPair<Rect, Double> allCandidates; // for all proto sizes in coarse image
      L<Int> pwScaled = uniquify(map(pw -> scaleDouble_iround(w, w1, pw), assumedProtoSizes));
      for (int pw : pwScaled) {
        // candidates are in full image resolution
        LPair<Rect, Double> candidates = rec.fullScanToNBest(proto, w1, pw, 0f, 3);
    
        printVars(+pwScaled, +candidates);
        allCandidates.addAll(candidates);
      }
      L<Rect> candidates = pairsA(takeFirst(5, sortBySecondOfPairsDesc_inPlace(allCandidates)));
      L<Pt> centers = centerOfRects(candidates);
      print(+candidates);
      print(+centers);
    
      // Stage 2: scan around candidates in higher resolution
    
      int h2 = rec.scaledInputImage(w2).getHeight();
      int spiralSize = w2/w1*2;
      int pixelsPerSpiral = sqr(spiralSize);
      print("Spiral size: " + spiralSize + " / " + pixelsPerSpiral);
    
      new Best<Rect> best;
      CheesyRecognizer.ScaledInputImage scaledInputImage = rec.scaledInputImage(w2);
      L<Int> pwScaled2 = uniquify(map(pw -> scaleDouble_iround(w, w2, pw), assumedProtoSizes));
      print(+pwScaled2);
      for (int pw : pwScaled2) {
        CheesyRecognizer.ScaledPrototype scaledProto = proto.scaledPrototype(pw);
        new Set<Pt> pointsTried;
        for (Pt p : centers) {
          // scaled center point, moved to top left of prototype
          Pt pScaled = translatePt(-pw/2, -scaledProto.getHeight()/2,
            scalePt(doubleRatio(w2, rec.getWidth()), p));
          //print(+pScaled);
          
          for (Pt p2 : pixelSpiral(pScaled.x, pScaled.y, w2, h2, pixelsPerSpiral)) {
            if (!pointsTried.add(p2)) continue;
      //print("Trying point " + p2);
            Pair<Rect, Double> result = rec.singleCheck(scaledInputImage, scaledProto, p2.x, p2.y, 0f);
            best.put(result);
          }
        }
      }
      Scored<Rect> bestInInputSpace = scored(scaleRect(doubleRatio(rec.getWidth(), w2), best!), best.score);
      print(bestInInputSpace);
    }
    
    setImage(inputImage);
    setSelection(bestInInputSpace!);
  }
}

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: #1027288
Snippet name: Vector Live Recognition Spike ["finds" the wrong spots?]
Eternal ID of this version: #1027288/5
Text MD5: d566e35ca21bb9bc22c893ea337d4bf2
Transpilation MD5: 1e04308c8aa45dcab4d0efb1a236d5ea
Author: stefan
Category: javax / maths
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-01 01:15:45
Source code size: 3010 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 152 / 1488
Version history: 4 change(s)
Referenced in: [show references]