sclass ChessOCR_TwoStageRecognizer implements Steppable { // input BufferedImage inputImage; Iterator rectStream; ChessPieceRecognizer pieceRecognizer; // internal new Set rectsTried; // output new Best> best; // rect + FEN *() {} *(ChessPieceRecognizer *pieceRecognizer, BufferedImage *inputImage, Iterator *rectStream) {} public bool step() { if (!rectStream.hasNext()) false; ret true with tryRect(rectStream.next()); } void tryRect(Rect r) { r = rectSetHeightToWidth(r); // square it if (!rectsTried.add(r)) ret; // seen BufferedImage board = clipBufferedImage(inputImage, r); S fen, double score = unpair chessOCR_recognizeBoard_FENAndScore(board, pieceRecognizer); best.put(pair(r, fen), score); } }