1 | sclass BWImageCategorizer { |
2 | new L<BWImage> images; |
3 | float allowedDistance = 0.1f; // allowed difference within category |
4 | |
5 | *() {} |
6 | *(float *allowedDistance) {} |
7 | |
8 | int locateImage(BWImage img) { |
9 | for i over images: |
10 | if (bwDistance(images.get(i), img, allowedDistance) <= allowedDistance) |
11 | ret i; |
12 | ret -1; |
13 | } |
14 | |
15 | int addImage(RGBImage img) { ret addImage(new BWImage(img)); } |
16 | |
17 | int addImage(BWImage img) { |
18 | int i = locateImage(img); |
19 | if (i >= 0) ret i; |
20 | images.add(img); |
21 | ret l(images)-1; |
22 | } |
23 | |
24 | int numCategories() { ret l(images); } |
25 | void clear() { images.clear(); } |
26 | |
27 | L<RGBImage> rgbImages() { ret bwImagesToRGB(images); } |
28 | |
29 | // find best fit regardless of distance |
30 | // returns Pair<index, confidence> |
31 | Pair<Int, Float> locateLax(BWImage img) { |
32 | new Lowest<Int> l; |
33 | for i over images: |
34 | l.put(i, bwDistance(images.get(i), img)); |
35 | ret pair(or(l.get(), -1), 1f-l.floatScoreOr(1)); |
36 | } |
37 | } |
Began life as a copy of #1006761
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1006771 |
Snippet name: | BWImageCategorizer |
Eternal ID of this version: | #1006771/5 |
Text MD5: | fe6e58b60aca8527f089fbd2da059d69 |
Author: | stefan |
Category: | javax / ocr |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-03-06 14:36:36 |
Source code size: | 987 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 567 / 1179 |
Version history: | 4 change(s) |
Referenced in: | [show references] |