Uses 911K of libraries. Click here for Pure Java version (14878L/83K).
1 | !7 |
2 | |
3 | cmodule PipelinedRecognizer > DynImageSurface { |
4 | transient ChessOCR_Pipeline activePipeline; |
5 | transient JTable tblBoardsFound; |
6 | transient ChessPieceRecognizer pieceRecognizer; |
7 | transient ReliableSingleThread rst = dm_rst(module(), r newRecognition); |
8 | transient S status; |
9 | transient bool preparing; |
10 | |
11 | start { |
12 | if (!hasImage()) setImage(whiteImage(100)); |
13 | onNewImage = rst; |
14 | rst.trigger(); |
15 | doEvery(1.0, r updateStatus); |
16 | } |
17 | |
18 | void updateStatus { |
19 | ChessOCR_Pipeline pipeline = activePipeline; |
20 | if (!preparing && (pipeline == null || pipeline.idle())) |
21 | setField(status := "Idle"); |
22 | else if (pipeline != null) |
23 | setField(status := "Recognizing. Segmenters: " + pipeline.segmenters.stats() + ", possible board positions: " + pipeline.possibleBoardPositions.stats()); |
24 | } |
25 | |
26 | void newRecognition { |
27 | dispose activePipeline; |
28 | if (!hasImage()) ret; |
29 | temp dm_tempSetField(preparing := true); |
30 | setField(status := "Recognizing..."); |
31 | new ChessOCR_Pipeline pipeline; |
32 | pipeline.inputImage = getImage(); |
33 | if (pieceRecognizer == null) |
34 | pieceRecognizer = chessOCR_pieceRecognizer(); |
35 | pipeline.pieceRecognizer = pieceRecognizer; |
36 | pipeline.boardsFound.onChange.add(r updateTable); |
37 | pipeline.boardsFound.onImprovedScore.add(voidfunc(S fen, Rect r) { |
38 | pipeline.possibleBoardPositions.addAll(wiggleRect(r)); |
39 | }); |
40 | activePipeline = pipeline; |
41 | |
42 | pipeline.addSegmenter(parameterizedSegmenterFromAGIBlue("GingerGM fullscreen find chess board #1")); |
43 | } |
44 | |
45 | void updateTable { |
46 | dataToTable(tblBoardsFound, sortedByMapElementDesc Score(map(activePipeline.boardsFound.byFEN, |
47 | (fen, data) -> litorderedmap( |
48 | "Score" := formatDouble(data.bestScore, 2), |
49 | "FEN" := fen, |
50 | "Best position" := strOrNull(data.bestPosition), |
51 | "#" := l(data.boardPositions))))); |
52 | } |
53 | |
54 | visual centerAndSouthWithMargins( |
55 | jvsplit(super, |
56 | jCenteredSection("Boards found", tblBoardsFound = sexyTable())), |
57 | dm_label status()); |
58 | |
59 | L<Rect> wiggleRect(Rect r) { |
60 | new L<Rect> out; |
61 | Rect img = imageRect(getImage()); |
62 | for y to 2: for x to 2: if (x > 0 || y > 0) |
63 | out.add(intersectRects(img, growRectRightAndBottom(r, x, y))); |
64 | ret out; |
65 | } |
66 | } |
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: | 222 / 547 |
Version history: | 19 change(s) |
Referenced in: | [show references] |