!7 srecord Entry(RGB color, double maxDistance) {} cmodule LearnActiveTab > DynSingleFunctionWithPrintLog { LPair scaledImages; void doIt { LPair data = gatherMarkedThingInImages(listImageFiles( //ai_browserTabsTrainingDataDir() aiImageAlbumDir() ), "Active tab"); pnlStruct(data); int gridSize = 4; scaledImages = new L; for (Pair p : data) { BufferedImage img = loadImage2(p.a); RGBImage rgb = RGBImage(scaleImageWithFactor(1.0/gridSize, img)); add(scaledImages, pair(rgb, scaleRect(p.b, 1.0/gridSize))); } RandomAndVary_Record rav = new(Entry, color := new RandomAndVary_RGB, maxDistance := new RandomAndVary_Double); Pair e = racerOptimize(rav, f score); print(e); } double score(Entry e) { int score = 0, count = 0; for (Pair p : scaledImages) { RGBImage img = p.a; int w = img.getWidth(), h = img.getHeight(); //printStructs(+w, +h, r := p.b); for y to h: for x to w: { bool detected = rgbDistance(img.getPixel(x, y), e.color) <= e.maxDistance; bool real = rectContains(p.b, x, y); score += detected == real ? 1 : 0; } count += w*h; } ret doubleRatio(score, count); } }