!7 cmodule ChessBoardRecognizer { S segmenterPreset; ParameterizedSegmenter segmenter; S status; transient ReliableSingleThread rst = dm_rst(module(), r recognize); transient BufferedImage img, board; transient ImageSurface isBoard; visual withCalc(rst, northCenterAndSouthWithMargins( withLabel("Segmenter preset: ", main.onChange(rst, dm_comboBox segmenterPreset(agiBlue_segmenterPresetNames()))), jSection("Chess board", isBoard = jImageSurface()), dm_label('status) )); void recognize { segmenter = parameterizedSegmenterFromAGIBlue(segmenterPreset); if (segmenter == null) ret with infoBox(status("No segmenter")); img = dm_shootScreenHidingOS(); L rects = segmenter.get(img); if (empty(rects)) ret with status("No chess board found"); Rect r = first(rects); if (l(rects) > 1) status("More than one chess board found, choosing one"); else status("Chess board found at: " + r); board = clipBufferedImage(img, r); if (isBoard != null) isBoard.setImage( mergeBufferedImagesVertically( map(bufferedImageNVerticalSlices(8, board), i -> mergeBufferedImagesHorizontally(bufferedImageNHorizontalSlices(8, i))))); } S status(S status) { setField(+status); ret status; } }