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

66
LINES

< > BotCompany Repo | #1024890 // Pipelined Chess Board Recognizer [dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (14878L/83K).

!7

cmodule PipelinedRecognizer > DynImageSurface {
  transient ChessOCR_Pipeline activePipeline;
  transient JTable tblBoardsFound;
  transient ChessPieceRecognizer pieceRecognizer;
  transient ReliableSingleThread rst = dm_rst(module(), r newRecognition);
  transient S status;
  transient bool preparing;

  start {
    if (!hasImage()) setImage(whiteImage(100));
    onNewImage = rst;
    rst.trigger();
    doEvery(1.0, r updateStatus);
  }
  
  void updateStatus {
    ChessOCR_Pipeline pipeline = activePipeline;
    if (!preparing && (pipeline == null || pipeline.idle()))
      setField(status := "Idle");
    else if (pipeline != null)
      setField(status := "Recognizing. Segmenters: " + pipeline.segmenters.stats() + ", possible board positions: " + pipeline.possibleBoardPositions.stats());
  }
  
  void newRecognition {
    dispose activePipeline;
    if (!hasImage()) ret;
    temp dm_tempSetField(preparing := true);
    setField(status := "Recognizing...");
    new ChessOCR_Pipeline pipeline;
    pipeline.inputImage = getImage();
    if (pieceRecognizer == null)
      pieceRecognizer = chessOCR_pieceRecognizer();
    pipeline.pieceRecognizer = pieceRecognizer;
    pipeline.boardsFound.onChange.add(r updateTable);
    pipeline.boardsFound.onImprovedScore.add(voidfunc(S fen, Rect r) {
      pipeline.possibleBoardPositions.addAll(wiggleRect(r));
    });
    activePipeline = pipeline;
    
    pipeline.addSegmenter(parameterizedSegmenterFromAGIBlue("GingerGM fullscreen find chess board #1"));
  }
  
  void updateTable {
    dataToTable(tblBoardsFound, sortedByMapElementDesc Score(map(activePipeline.boardsFound.byFEN,
      (fen, data) -> litorderedmap(
        "Score" := formatDouble(data.bestScore, 2),
        "FEN" := fen,
        "Best position" := strOrNull(data.bestPosition),
        "#" := l(data.boardPositions)))));
  }
  
  visual centerAndSouthWithMargins(
    jvsplit(super,
      jCenteredSection("Boards found", tblBoardsFound = sexyTable())),
    dm_label status());
    
  L<Rect> wiggleRect(Rect r) {
    new L<Rect> out;
    Rect img = imageRect(getImage());
    for y to 2: for x to 2: if (x > 0 || y > 0)
      out.add(intersectRects(img, growRectRightAndBottom(r, x, y)));
    ret out;
  }
}

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: #1024890
Snippet name: Pipelined Chess Board Recognizer [dev.]
Eternal ID of this version: #1024890/20
Text MD5: 7c300aaa5e4cf7150c58957118a7aa94
Transpilation MD5: 545930a8a1e8f57437b7088f32f2cf8d
Author: stefan
Category: javax / chess ocr
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-28 23:05:24
Source code size: 2309 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 223 / 548
Version history: 19 change(s)
Referenced in: