Uses 1059K of libraries. Click here for Pure Java version (12314L/66K).
1 | !7 |
2 | |
3 | set flag BWIntegralImage_brightnessCheat. |
4 | set flag BWIntegralImage_useVectorAPI. |
5 | |
6 | cmodule2 IILineFinder > DynImageSurfaceAndEnabled { |
7 | switchable int imageSize = 1000; |
8 | switchable int warmups = 10; // per round |
9 | switchable int initialWarmups = 100000; |
10 | switchable int stripes = 2; // how many threads to use for making integral image |
11 | ExpectedAndActual<Pair<Pt>> lastError; |
12 | |
13 | transient Pair<Pt> actual, recognized; |
14 | transient IBWIntegralImage ii; |
15 | transient ImageSurface isReconstructed; |
16 | transient S status, errorStatus; |
17 | transient new Scorer scorer; |
18 | transient new Average conversionTime, recTime; |
19 | transient NotTooOften clearRecTime = nto_everyTenSeconds(); |
20 | transient long rounds; |
21 | transient autoDispose ThreadPoolExecutor executor = defaultThreadPoolExecutor(); |
22 | |
23 | visualize { |
24 | JComponent c = centerAndSouthWithMargin( |
25 | jhgrid(jCenteredSection_fontSizePlus(10, "Input", super.visualize()), |
26 | jCenteredSection_fontSizePlus(10, "Recognition", jscroll_centered(isReconstructed = doubleBufferedImageSurface()))), |
27 | jvstack(fontSizePlus(10, dm_centeredLabel status()), fontSizePlus(5, dm_centeredLabel errorStatus()))); |
28 | enableDoubleBuffering(); |
29 | ret c; |
30 | } |
31 | |
32 | start { |
33 | thread "Calc" enter { |
34 | while (true) { |
35 | if (deleted()) ret; |
36 | if (!enabled) continue with sleepSeconds(1); |
37 | pcall { |
38 | if (clearRecTime!) { |
39 | recTime.clear(); |
40 | conversionTime.clear(); |
41 | } |
42 | makeImage(); |
43 | recognize(); |
44 | score(); |
45 | reconstruct(); |
46 | status(); |
47 | } |
48 | } |
49 | } |
50 | } |
51 | |
52 | void makeImage { |
53 | Pt a = randomPt(imageSize), b = randomPt(imageSize); |
54 | LineWithColor line = new(a, b, Color.black, 1); |
55 | BufferedImage img = renderBackgroundPlusLines(imageSize, imageSize, new BackgroundPlus(Color.white, line)); |
56 | setImage(img); |
57 | long time = nanoTime(); |
58 | ii = stripedBWIntegralImage(executor, stripes, img); |
59 | conversionTime.add(nanoTime()-time); |
60 | actual = sortedPair(a, b); |
61 | } |
62 | |
63 | void recognize { |
64 | int w = rounds == 0 ? initialWarmups : warmups; |
65 | ++rounds; |
66 | repeat w { bwii_detectSingleLine(ii); } |
67 | long time = nanoTime(); |
68 | Pair<Pt> output = bwii_detectSingleLine(ii); |
69 | recTime.add(nanoTime()-time); |
70 | recognized = sortedPair(output); |
71 | } |
72 | |
73 | void score { |
74 | bool ok = eq(actual, recognized); |
75 | scorer.add(ok); |
76 | if (!ok) setField(lastError := ExpectedAndActual(actual, recognized)); |
77 | } |
78 | |
79 | void reconstruct { |
80 | BufferedImage img = renderBackgroundPlusLines(imageSize, imageSize, new BackgroundPlus(Color.white, LineWithColor(actual.a, actual.b, Color.black, 1))); |
81 | isReconstructed.setImage(img); |
82 | } |
83 | |
84 | void status { |
85 | setFields( |
86 | status := joinNemptiesWithComma( |
87 | "Image size: " + toMillion(sqr(imageSize), 1) + " MP, conversion time: " + n2_iround(conversionTime!) + " ns", |
88 | "recognition time: " + n2_iround(recTime!) + " ns", |
89 | scorer), |
90 | errorStatus := lastError == null ?: "last error: " + lastError); |
91 | } |
92 | } |
Began life as a copy of #1030512
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030524 |
Snippet name: | Microsecond Line Finder v1, JDK 16 version with vector API |
Eternal ID of this version: | #1030524/8 |
Text MD5: | 7911cab1cf2f01f0331fbb4e6e2c5708 |
Transpilation MD5: | 64b4a91c2403c40ceebcdebf29f4c412 |
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: | 2021-01-07 03:01:16 |
Source code size: | 3123 bytes / 92 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 203 / 550 |
Version history: | 7 change(s) |
Referenced in: | [show references] |