Libraryless. Click here for Pure Java version (16304L/116K).
abstract sclass ChessOCR_DynTestBoardFinders > DynSingleFunctionWithPrintLog { replace Segmenter with IF1<BufferedImage, L<Rect>>. S scoreModule; long maxMBs = 256; // save dat memory transient L<Result> results = syncList(); new Best<S> best; int triesAllowed = 10; // how many rects each segmenter may produce transient long dataSize; transient new L<TestImage> images; transient JProgressBar progressBar; // result for segmenter srecord noeq Result( S segmenterName, Segmenter segmenter, double score, Map<TestResult, Double> individualScores) {} // individual test result srecord noeq TestResult( TestImage test, L<Rect> rectsFound ) {} srecord noeq TestImage(S caseName, BufferedImage img, Rect boardLocation) { toString { ret caseName; } } bool spaceToSpare() { ret toMB(dataSize) < maxMBs; } void doIt { prepare(); results.clear(); dm_call(scoreModule, 'clear); Cl<S> presets = agiBlue_chessBoardSegmenterPresetNames(); for ping (S preset : iterateUpdatingProgressBar(progressBar, presets)) _testSegmenter(preset, parameterizedSegmenterFromAGIBlue(preset)); } void prepare runInQAndWait { if (empty(images)) loadImages(); if (!dm_moduleExists(scoreModule)) setField(scoreModule := dm_showNewModule("#1024787/ScoreMatrix")); else dm_activateModule(scoreModule); } Result scoreSegmenter(S name, Segmenter seg) { Result result = new(name, seg, 0, new LinkedHashMap); try { new Scorer scorer; for (TestImage img : images) { L<Rect> out = seg.get(img.img); double tolerance = imageDiameter(img.img)/48; double score2 = 0; for (Rect r : takeFirst(triesAllowed, out)) score2 = max(score2, video_scoreRect_score(img.boardLocation, r, tolerance)); print("Score: " + score2); scorer.addZeroToOne(score2); result.individualScores.put(new TestResult(img, out), score2); } print(scorer); result.score = scorer.score(); } catch print e { print("SEGMENTER TOTAL FAIL"); } ret result; } void loadImages { LPair<S, Rect> in = asLinkedList(agiBlue_chess_trainingImagesWithBoardLocations()); while (nempty(in)) { if (!spaceToSpare()) break with print("Out of space (" + toM(dataSize) + " MB used), skipping " + nImages(in)); S name, Rect location = unpair popFirst(in); pcall { BufferedImage img = loadImage2(parseImageSnippetURL(agiBlue_lookupInSlice(agiBlue_chessBoardRecognitionTrainingImagesSliceID(), name, "input image"))); images.add(new TestImage(name, img, location)); dataSize += bufferedImageDataSize(img); print("Have " + nImages(images) + ", data size: " + toM(dataSize) + " MB"); } } print("Loading done"); } start { setFunctionName("Run tests"); } visual centerAndSouthWithMargin(super, withMargin(progressBar = jProgressBarWithText())); void _testSegmenter(S name, Segmenter seg) { prepare(); Result r = scoreSegmenter(name, seg); print("Score for " + name + ": " + r.score); results.add(r); if (best.put(name, r.score)) print("NEW BEST!"); change(); dm_call(scoreModule, 'add, dm_call(scoreModule, 'newEntry, r.segmenterName, r.score, r.individualScores)); } // API void testSegmenter(S name, virtual Segmenter _seg) { Segmenter seg = img -> (L<Rect>) quickImport(callF(_seg, img)); _testSegmenter(name, seg); } }
Began life as a copy of #1024783
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: | #1024846 |
Snippet name: | ChessOCR_DynTestBoardFinders |
Eternal ID of this version: | #1024846/13 |
Text MD5: | 4857332b7104f000c8ee8e47ec56c97a |
Transpilation MD5: | 20976742d9c9e56d9a3a90ecf3c5ace8 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-08-29 13:18:09 |
Source code size: | 3675 bytes / 113 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 306 / 735 |
Version history: | 12 change(s) |
Referenced in: | [show references] |