Uses 911K of libraries. Click here for Pure Java version (11807L/64K).
1 | !7 |
2 | |
3 | cmodule LearnDogsVsCats > DynSingleFunctionWithPrintLog { |
4 | /*switchable*/ transient File dir = userDir("dev/dogs-vs-cats/train"); |
5 | transient int eyeWidth = /*32*/10; |
6 | transient double eyeSurround = 0.5; |
7 | |
8 | transient L<File> allImageFiles; |
9 | transient L<BWImage> allEyeImages; |
10 | transient Map<BWImage, File> eyeImageSources; |
11 | transient ImageSurface is, isFound; |
12 | |
13 | start { |
14 | if (!dm_osBooting()) |
15 | thread { doIt(); } |
16 | } |
17 | |
18 | JComponent makeButtons() { |
19 | ret hstackWithSpacing(super.makeButtons(), |
20 | jbutton("Random Image", rThread randomImage)); |
21 | } |
22 | |
23 | void randomImage { |
24 | recognizeImage(random(allImageFiles)); |
25 | } |
26 | |
27 | void doIt { |
28 | // load scaled down test images |
29 | |
30 | allImageFiles = listImageFiles(dir); |
31 | Map<File, LPair<Rect, S>> markingsMap = new Map; |
32 | for (File f : allImageFiles) |
33 | mapPutIfNemptyValue(markingsMap, f, loadImageFileMarkings(f)); |
34 | pnlStruct(markingsMap); |
35 | if (empty(markingsMap)) ret with print("No marked images found in " + dir); |
36 | |
37 | new Map<File, BWIntegralImage> iImages; |
38 | for (File f : keys(markingsMap)) |
39 | iImages.put(f, BWIntegralImage(f)); |
40 | print("Have " + n2(iImages, "integral image") + ", total size: " + str_toM(deepObjectSize(iImages))); |
41 | |
42 | allEyeImages = new L; |
43 | eyeImageSources = new Map; |
44 | for (File f : keys(markingsMap)) |
45 | if (fileNameContains(f, "cat")) |
46 | for (Pair<Rect, S> mark : markingsMap.get(f)) |
47 | if (eqic(mark.b, "eye")) { |
48 | BWImage img = bwResizeSmooth(iBWImageToBWImage(safeClipIBWImage(virtualScaledIntegralImageBW(iImages.get(f)), |
49 | growRectProportionally(eyeSurround, mark.a) |
50 | )), eyeWidth); |
51 | allEyeImages.add(img); |
52 | eyeImageSources.put(img, f); |
53 | } |
54 | //showImage(mergeBWImagesVertically(allEyeImages)); |
55 | |
56 | //showImage(scaleDownUsingIntegralImageBW(random(values(iImages)), 256)); |
57 | //showImage(iBWImageToBWImage(virtualScaledIntegralImageBW(random(values(iImages)), 256))); |
58 | |
59 | //File f = random(allImageFiles); |
60 | File f = firstFileWithName(allImageFiles, "cat.2516.jpg"); |
61 | |
62 | recognizeImage(f); |
63 | } |
64 | |
65 | void recognizeImage(File f) { |
66 | print(f); |
67 | |
68 | BWII_MultiPatternFinder finder = new(allEyeImages, BWIntegralImage(f)); |
69 | disposePIFrame(is); |
70 | is = null; |
71 | |
72 | for (FoundImg found : finder) { |
73 | if (is == null || is.getImage().getWidth() != finder.currentScaleWidth) |
74 | is = showImage(is, iBWImageToBWImage(finder.scaled)); |
75 | print(found + " / " + eyeImageSources.get(finder.pattern)); |
76 | overlaySelectionsOnImageSurface(is, ll(foundImgRect(found))); |
77 | isFound = showZoomedImage(isFound, "Found", finder.pattern); |
78 | } |
79 | } |
80 | } |
Began life as a copy of #1022975
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1022991 |
Snippet name: | Learn Dogs vs Cats Prelude v2 [dev.] |
Eternal ID of this version: | #1022991/12 |
Text MD5: | ef5a48618637a88d9d77ed8e1b5f76c1 |
Transpilation MD5: | 8b95840bc60470e563a55848f9ae77b0 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-04-17 17:25:15 |
Source code size: | 2773 bytes / 80 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 320 / 590 |
Version history: | 11 change(s) |
Referenced in: | [show references] |