Uses 911K of libraries. Click here for Pure Java version (5731L/32K).
1 | !7 |
2 | |
3 | // uses only one prototype image |
4 | // goes through different granularities at once |
5 | |
6 | cmodule ImageRecogSpike {
|
7 | switchable S prototypeImageID = #1102884; |
8 | switchable S inputImageID = #1102883; |
9 | |
10 | // how big do we think the prototype is in the whole image |
11 | // (percentage by height) |
12 | transient double assumedPrototypeHeightPercentage = 70; |
13 | |
14 | transient L<Int> widths = ll(32, 64, 128); |
15 | transient new L<IBWIntegralImage> integralImages; |
16 | transient BWIntegralImage baseImage; |
17 | transient JTabbedPane tabs = jTabbedPane(); |
18 | transient BWImage prototypeImage; |
19 | transient new L<OneLevel> levels; // recognizers for each granularity |
20 | |
21 | class OneLevel extends SteppableAndBest<Rect> {
|
22 | IBWIntegralImage ii; // scaled integral image |
23 | BWImage image; // scaled image |
24 | BWImage prototype; // scaled prototype |
25 | float minSimilarity = 0.5f; |
26 | ImageSurface is; |
27 | |
28 | *(IBWIntegralImage *ii) {
|
29 | image = iBWIntegralImageToBWImage(ii); |
30 | // get assumed height of prototype in scaled-down image |
31 | int ph = iround(ii.getHeight()*assumedPrototypeHeightPercentage/100.0); |
32 | // resize prototype |
33 | prototype = bwResizeToHeightSmooth(prototypeImage, ph); |
34 | addTab(tabs, "proto " + ii.getWidth(), |
35 | jFullCenterScroll(jPixelatedZoomedImageSurface(4.0, prototype))); |
36 | } |
37 | |
38 | public bool step() {
|
39 | FoundImg fi = bwImageSearch_best(image, prototype, minSimilarity); |
40 | print("Search result: " + fi);
|
41 | if (fi != null) {
|
42 | best.put(fi.r, fi.sim); |
43 | setImageSurfaceSelection(is, best!); |
44 | } |
45 | false; // done |
46 | } |
47 | } |
48 | |
49 | start-thread {
|
50 | if (baseImage == null) |
51 | baseImage = BWIntegralImage(loadImage2(inputImageID)); |
52 | if (prototypeImage == null) |
53 | prototypeImage = loadBWImage(prototypeImageID); |
54 | for (int w : widths) {
|
55 | IBWIntegralImage ii = scaledIBWIntegralImage(baseImage, w); |
56 | integralImages.add(ii); |
57 | ImageSurface is = jPixelatedZoomedImageSurface( |
58 | doubleRatio(baseImage.getWidth(), w), iBWIntegralImageToBWImage(ii)); |
59 | addTab(tabs, "w=" + w, jFullCenterScroll(is)); |
60 | levels.add(setAll(new OneLevel(ii), +is)); |
61 | } |
62 | addTab(tabs, "Prototype", jFullCenterScroll(jPixelatedZoomedImageSurface(4, prototypeImage))); |
63 | |
64 | time "Process" {
|
65 | for (OneLevel lvl : levels) |
66 | lvl.step(); |
67 | } |
68 | } |
69 | |
70 | visual tabs; |
71 | } |
Began life as a copy of #1027204
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1027213 |
| Snippet name: | Image Recognition for Vector Spike (backup 1) |
| Eternal ID of this version: | #1027213/1 |
| Text MD5: | e61955f1268515d9e9a64167297bcea9 |
| Transpilation MD5: | 4b041530a7e0cd114cfa4230b7db3962 |
| Author: | stefan |
| Category: | javax / image recognition |
| Type: | JavaX source code (Dynamic Module) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-02-26 12:17:13 |
| Source code size: | 2415 bytes / 71 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 490 / 639 |
| Referenced in: | [show references] |