Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

42
LINES

< > BotCompany Repo | #1024771 // ChessOCR_SquareImagesCollector - extract chess piece images from training screenshots on agi.blue

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (8556L/59K).

1  
sclass ChessOCR_SquareImagesCollector {
2  
  new Set<S> imageMD5s;
3  
  L<ChessOCR_PieceImage> allImages = syncList();
4  
  
5  
  VF2<S, Rect> onBoardFound; // image name, board rects
6  
  
7  
  void loadImagesFromAGIBlue {
8  
    for (S name, fen : unpair agiBlue_chess_trainingImagesWithPositions()) {
9  
      SS map = pairsToCIMap(agiBlue_lookupMultipleKeys(agiBlue_chessBoardRecognitionTrainingImagesSliceID(),
10  
        name, ll("Input image", "Segmenter used", "Chess board found", "Board location")));
11  
      if (!isYes(map.get("Chess board found"))) continue with print("Chess board not found, skipping");
12  
      BufferedImage img = loadImage2(parseImageSnippetURL(map.get("input image")));
13  
      Rect r = safeUnstructRect(map.get("Board location"));
14  
      if (r == null) continue with print("No board? Skipping");
15  
      print("Board: " + r.w + "*" + r.h);
16  
      callF(onBoardFound, name, r);
17  
      if (abs(r.w-r.h) > 3) continue with print("Board not square, skipping");
18  
      BufferedImage board = clipBufferedImage(img, r);
19  
      LS position = chess_parseFEN(fen);
20  
      printStruct(+position);
21  
      
22  
      LL<BufferedImage> squareImages = map2 cloneBufferedImage(bufferedImageMNGrid(board, 8, 8));
23  
    
24  
      for row to 8: {
25  
        S fenLine = position.get(row);
26  
        L<BufferedImage> images = squareImages.get(row);
27  
        for col to 8:
28  
          if (imageMD5s.add(imageMD5(images.get(col))))
29  
            allImages.add(new ChessOCR_PieceImage(
30  
              chess_xyToSquare(col, row),
31  
              chess_parseFENSymbol(fenLine.charAt(col)),
32  
              images.get(col)));
33  
      }
34  
    }
35  
    
36  
    print("Have " + n2(allImages, "chess square image"));
37  
  }
38  
  
39  
  LPair<S, BufferedImage> allImages() {
40  
    ret map(cloneList(allImages), i -> pair(i.piece, i.img));
41  
  }
42  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1024771
Snippet name: ChessOCR_SquareImagesCollector - extract chess piece images from training screenshots on agi.blue
Eternal ID of this version: #1024771/11
Text MD5: 18a134722eaa674889b3fdeb0d98f934
Transpilation MD5: 2fc227ee68f084671763871762157c58
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-29 13:44:41
Source code size: 1800 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 293 / 1163
Version history: 10 change(s)
Referenced in: [show references]