!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 assumedProtoSizes = sqrt2progression_int_dropFirst(5, w); print(+assumedProtoSizes); time "Recog" { // Look for center-of-object candidates in coarse resolution new LPair allCandidates; // for all proto sizes in coarse image L pwScaled = uniquify(map(pw -> scaleDouble_iround(w, w1, pw), assumedProtoSizes)); for (int pw : pwScaled) { // candidates are in full image resolution LPair candidates = rec.fullScanToNBest(proto, w1, pw, 0f, 3); printVars(+pwScaled, +candidates); allCandidates.addAll(candidates); } L candidates = pairsA(takeFirst(5, sortBySecondOfPairsDesc_inPlace(allCandidates))); L 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 best; CheesyRecognizer.ScaledInputImage scaledInputImage = rec.scaledInputImage(w2); L pwScaled2 = uniquify(map(pw -> scaleDouble_iround(w, w2, pw), assumedProtoSizes)); print(+pwScaled2); for (int pw : pwScaled2) { CheesyRecognizer.ScaledPrototype scaledProto = proto.scaledPrototype(pw); new Set 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 result = rec.singleCheck(scaledInputImage, scaledProto, p2.x, p2.y, 0f); best.put(result); } } } Scored bestInInputSpace = scored(scaleRect(doubleRatio(rec.getWidth(), w2), best!), best.score); print(bestInInputSpace); } setImage(inputImage); setSelection(bestInInputSpace!); } }