Libraryless. Click here for Pure Java version (7753L/52K).
1 | // type parameter is rect + FEN |
2 | // not persistable |
3 | sclass ChessOCR_TwoStageRecognizer extends SteppableAndBest<Pair<Rect, S>> { |
4 | replace Segmenter with IF1<BufferedImage, L<Rect>>. |
5 | |
6 | // input |
7 | BufferedImage inputImage; |
8 | Iterator<? extends Segmenter> segmenterStream; |
9 | ChessPieceRecognizer pieceRecognizer; |
10 | bool verbose; |
11 | |
12 | // internal |
13 | L<Rect> rectQueue = syncLinkedList(); |
14 | new Set<Rect> rectsTried; |
15 | |
16 | *() {} |
17 | *(ChessPieceRecognizer *pieceRecognizer, BufferedImage *inputImage, Iterator<? extends Segmenter> *segmenterStream) {} |
18 | |
19 | public bool step() { |
20 | if (nempty(rectQueue)) |
21 | ret true with tryRect(popFirst(rectQueue)); |
22 | if (segmenterStream.hasNext()) { |
23 | Segmenter seg = segmenterStream.next(); |
24 | if (seg == null) true; |
25 | L<Rect> rects = seg.get(inputImage); |
26 | addAll(rectQueue, rects); |
27 | if (verbose) print("Segmenter " + seg + " returned: " + rects); |
28 | true; |
29 | } |
30 | false; |
31 | } |
32 | |
33 | // returns true if rect not seen before |
34 | bool tryRect(Rect r) { |
35 | r = rectSetHeightToWidth(r); // square it |
36 | if (!rectsTried.add(r)) false; // seen |
37 | BufferedImage board = clipBufferedImage(inputImage, r); |
38 | S fen, double score = unpair chessOCR_recognizeBoard_FENAndScore(board, pieceRecognizer); |
39 | if (verbose) print("Score " + score + " for rect: " + r); |
40 | best.put(pair(r, fen), score); |
41 | true; |
42 | } |
43 | |
44 | void verbose(bool verbose) { |
45 | best.verboseNewBest = this.verbose = verbose; |
46 | } |
47 | |
48 | Rect bestBoardLocation() { ret pairA(best!); } |
49 | Pair<Rect, Double> boardLocationAndScore() { ret pair(pairA(best!), score()); } |
50 | } |
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: | #1024813 |
Snippet name: | ChessOCR_TwoStageRecognizer |
Eternal ID of this version: | #1024813/16 |
Text MD5: | 5a74bac35875500579d30957d305e37e |
Transpilation MD5: | 59c279b13a4f47d0c60a41c7c79539d8 |
Author: | stefan |
Category: | javax / chess ocr |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-08-28 15:38:59 |
Source code size: | 1634 bytes / 50 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 309 / 770 |
Version history: | 15 change(s) |
Referenced in: | [show references] |