!7 module WebCamToImageBuckets > DynPrintLogAndEnabled { transient int width = 16; transient float minScore = 0.99f; transient int maxImages = 1000; transient BufferedImage lastImage; transient new LL buckets; transient int images; S switchableFields() { ret 'width; } start { doEvery(1000, rstUpdate()); } void update { if (!enabled || images >= maxImages) ret; final BufferedImage img = dm_webCamImage(); afterwards { lastImage = img } if (img == null || img == lastImage) ret; RGBImage pat = RGBImage(resizeImage(img, width)); long time = sysNow(); new Best best; for i over buckets: { Pair p = rgbMostSimilarImage(pat, buckets.get(i), 0); best.put(i, p.b); } done2_always_timeFirst(time, "Images/buckets: " + images + "/" + l(buckets) + ". Best bucket: " + best + " (" + map l(buckets) + ")"); ++images; if (best.score() < minScore) { print("Opening new bucket"); buckets.add(ll(pat)); } else buckets.get(best!).add(pat); } }