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

1  
!7
2  
3  
cmodule VectorLiveRecogSpike1 > DynImageSurfaceAndEnabled {
4  
  transient ReliableSingleThread rstRecog = dm_rst(this, r recognize);
5  
  
6  
  start {
7  
    rstRecog.trigger();
8  
    dm_vmBus_onMessage haveVectorImage((mod, _img) -> rstRecog.trigger());
9  
  }
10  
  
11  
  void recognize {
12  
    if (!enabled) ret;
13  
    BufferedImage inputImage = dm_getLatestVectorImage();
14  
    CheesyRecognizer rec = new(inputImage);
15  
    CheesyRecognizer.Prototype proto = rec.addPrototype(loadBWImage(#1102893));
16  
    int w = rec.getWidth(); // input image width
17  
    int w1 = 16; // coarse resolution to scan
18  
    int w2 = 128; // fine resolution to scan
19  
    print(+w);
20  
    L<Int> assumedProtoSizes = sqrt2progression_int_dropFirst(5, w);
21  
    print(+assumedProtoSizes);
22  
    time "Recog" {
23  
      // Look for center-of-object candidates in coarse resolution
24  
    
25  
      new LPair<Rect, Double> allCandidates; // for all proto sizes in coarse image
26  
      L<Int> pwScaled = uniquify(map(pw -> scaleDouble_iround(w, w1, pw), assumedProtoSizes));
27  
      for (int pw : pwScaled) {
28  
        // candidates are in full image resolution
29  
        LPair<Rect, Double> candidates = rec.fullScanToNBest(proto, w1, pw, 0f, 3);
30  
    
31  
        printVars(+pwScaled, +candidates);
32  
        allCandidates.addAll(candidates);
33  
      }
34  
      L<Rect> candidates = pairsA(takeFirst(5, sortBySecondOfPairsDesc_inPlace(allCandidates)));
35  
      L<Pt> centers = centerOfRects(candidates);
36  
      print(+candidates);
37  
      print(+centers);
38  
    
39  
      // Stage 2: scan around candidates in higher resolution
40  
    
41  
      int h2 = rec.scaledInputImage(w2).getHeight();
42  
      int spiralSize = w2/w1*2;
43  
      int pixelsPerSpiral = sqr(spiralSize);
44  
      print("Spiral size: " + spiralSize + " / " + pixelsPerSpiral);
45  
    
46  
      new Best<Rect> best;
47  
      CheesyRecognizer.ScaledInputImage scaledInputImage = rec.scaledInputImage(w2);
48  
      L<Int> pwScaled2 = uniquify(map(pw -> scaleDouble_iround(w, w2, pw), assumedProtoSizes));
49  
      print(+pwScaled2);
50  
      for (int pw : pwScaled2) {
51  
        CheesyRecognizer.ScaledPrototype scaledProto = proto.scaledPrototype(pw);
52  
        new Set<Pt> pointsTried;
53  
        for (Pt p : centers) {
54  
          // scaled center point, moved to top left of prototype
55  
          Pt pScaled = translatePt(-pw/2, -scaledProto.getHeight()/2,
56  
            scalePt(doubleRatio(w2, rec.getWidth()), p));
57  
          //print(+pScaled);
58  
          
59  
          for (Pt p2 : pixelSpiral(pScaled.x, pScaled.y, w2, h2, pixelsPerSpiral)) {
60  
            if (!pointsTried.add(p2)) continue;
61  
      //print("Trying point " + p2);
62  
            Pair<Rect, Double> result = rec.singleCheck(scaledInputImage, scaledProto, p2.x, p2.y, 0f);
63  
            best.put(result);
64  
          }
65  
        }
66  
      }
67  
      Scored<Rect> bestInInputSpace = scored(scaleRect(doubleRatio(rec.getWidth(), w2), best!), best.score);
68  
      print(bestInInputSpace);
69  
    }
70  
    
71  
    setImage(inputImage);
72  
    setSelection(bestInInputSpace!);
73  
  }
74  
}

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: 223 / 1582
Version history: 4 change(s)
Referenced in: [show references]