!7 static int topTenSize = 1000; static MultiSetAndTopTen mstt; // holds md5 p { mstt = new MultiSetAndTopTen( l_persistentTreeMap("Images + count"), l_persistentList("Top Ten")); f (l(mstt.topTen()) != topTenSize) mstt.newTopTenSize(topTenSize); thread "Collect" { repeat with sleep 10 { collectIt(); } } showButtons("Top " + topTenSize, f showTopTen); } svoid collectIt { print("Collecting..."); BWImage img = shootScreenBW(); L segments = autoSegment(img); for (Rect r : segments) { RGBImage clip = img.clip(r).toRGB(); S md5 = rgbMD5(clip); mstt.add(md5); File f = imgFile(md5); if (!f.exists()) savePNG(f, clip); } print(n(segments, "segment") + " on screen. " + n(mstt.numEntries(), "image") + " in DB. " + n(mstt.numOccurrences(), "occurrence") + " recorded."); } static File imgFile(S md5) { ret getProgramFile(md5 + ".png"); } svoid showTopTen { showTable(map(mstt.topTen(), func(S md5) { litorderedmap("Image" := loadBufferedImageOpt(imgFile(md5)), "MD5" := md5, "Occurrences" := mstt.get(md5)) }), "Top Ten"); }