Uses 5262K of libraries. Click here for Pure Java version (2307L/16K/59K).
1 | !752 |
2 | |
3 | !include #1004250 // Eye |
4 | |
5 | static S imageID = "#1004248"; |
6 | |
7 | static JTable table; |
8 | static BufferedImage image; |
9 | static RGBImage rgbImage; |
10 | static BWImage bwImage; |
11 | static ImageSurface imageSurface; |
12 | static new L<Map> data; |
13 | static JFrame imageFrame; |
14 | static new Map<S, S> comments; |
15 | |
16 | static ImageReader recognizer; // just for compiling |
17 | |
18 | p { |
19 | imageID = or2(get(args, 0), imageID); |
20 | |
21 | image = loadImage2(imageID); |
22 | imageSurface = showImage(image, "The Image [" + imageID + "]"); |
23 | imageSurface.setZoom(2); |
24 | |
25 | /* |
26 | ri = new XRecognizableImage; |
27 | //ri.imageInfo = ii; |
28 | ri.setImage(image); |
29 | ri.imageSurface.setZoom(2); |
30 | ri.setDrawMarkLines(true); |
31 | ri.setDrawConfidenceBoxes(true); |
32 | imageFrame = showFrame("The Image [" + imageID + "]", ri); |
33 | frameIcon(imageFrame, "#1004230"); |
34 | moveToTopRightCorner(imageFrame); |
35 | */ |
36 | |
37 | // hints |
38 | |
39 | hint("There are 6 letters"); |
40 | |
41 | // compute stuff |
42 | |
43 | addLine("Image Size", "Image size is " + iW() + " * " + iH() + " px"); |
44 | addLine("Flexible Segmenter", func { |
45 | L<Segment> segments = new FlexibleSegmenter().segment(iBW()); |
46 | ret segmentsToString(segments); |
47 | }); |
48 | |
49 | rebuildTable(); |
50 | tableColumnMaxWidth(table, 0, 200); |
51 | |
52 | onDoubleClickOrEnter(table, voidfunc(int row) { |
53 | Map map = getTableLineAsMap(table, row); |
54 | if (map == null) ret; |
55 | S text = getString(map, "Text"); |
56 | showBoxes(findBoxes(text)); |
57 | }); |
58 | } |
59 | |
60 | svoid addLine(S who, O gen) { |
61 | S line; |
62 | if (gen instanceof S) |
63 | line = (S) gen; |
64 | else try { |
65 | line = str(callF(gen)); |
66 | } catch e { |
67 | who = "[Error] " + who; |
68 | e.printStackTrace(); |
69 | line = exceptionToStringShort(e); |
70 | } |
71 | data.add(litorderedmap("Who", who, "Text", line)); |
72 | } |
73 | |
74 | svoid hint(S text) { |
75 | addLine("Hint", text); |
76 | } |
77 | |
78 | static int iW() { |
79 | ret iB().getWidth(); |
80 | } |
81 | |
82 | static int iH() { |
83 | ret iB().getHeight(); |
84 | } |
85 | |
86 | static BufferedImage iB() { |
87 | ret image; |
88 | } |
89 | |
90 | static RGBImage iRGB() { |
91 | if (rgbImage == null) |
92 | rgbImage = new RGBImage(image); |
93 | ret rgbImage; |
94 | } |
95 | |
96 | static BWImage iBW() { |
97 | if (bwImage == null) |
98 | bwImage = new BWImage(image); |
99 | ret bwImage; |
100 | } |
101 | |
102 | static S segmentsToString(L<Segment> l) { |
103 | ret join(" ", map(func(Segment s) { rectToString(s.boundingBox) }, l)); |
104 | } |
105 | |
106 | static S rectToString(Rectangle r) { |
107 | ret "[" + r.x + " " + r.y + " " + r.width + " " + r.height + "]"; |
108 | } |
109 | |
110 | svoid showBoxes(L<Rectangle> l) { |
111 | print("Showing boxes: " + struct(l)); |
112 | /* |
113 | new L<DebugItem> di; |
114 | int n = 0; |
115 | for (Rectangle r : l) { |
116 | ++n; |
117 | Subrecognition sr = new Subrecognition(r, null, null, "Box " + n); |
118 | di.add(new DebugItem("bla", sr)); |
119 | } |
120 | */ |
121 | BufferedImage img = copyImage(image); |
122 | drawBoxes(img, l, Color.red, 0.5f); |
123 | imageSurface.setImage(img); |
124 | //ri.setDebugInfo(di); |
125 | //ri.repaintImageSurface(); |
126 | } |
127 | |
128 | static L<Rectangle> findBoxes(S s) { |
129 | L<S> tok = javaTok(s); |
130 | new L<Rectangle> boxes; |
131 | for (int i = 1; i < l(tok); i += 2) { |
132 | if (eq(tok.get(i), "[")) try { |
133 | int x = parseInt(get(tok, i+2)); |
134 | int y = parseInt(get(tok, i+4)); |
135 | int w = parseInt(get(tok, i+6)); |
136 | int h = parseInt(get(tok, i+8)); |
137 | boxes.add(new Rectangle(x, y, w, h)); |
138 | } catch {} |
139 | } |
140 | ret boxes; |
141 | } |
142 | |
143 | svoid addComment(S text, S comment) { |
144 | comments.put(text, comment); |
145 | for (Map m : data) |
146 | if (eq(text, get(m, "Text"))) |
147 | m.put("Comment", comment); |
148 | rebuildTable(); |
149 | } |
150 | |
151 | svoid rebuildTable() { |
152 | table = showTable(table, data, "Image Analysis"); |
153 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004246 |
Snippet name: | Some Simple Image Analysis |
Eternal ID of this version: | #1004246/1 |
Text MD5: | d32fabdafacb5563cfab536cab37538b |
Transpilation MD5: | 180cdf1067a7379375f24391cdc943a3 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-08-12 17:57:30 |
Source code size: | 3511 bytes / 153 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 698 / 815 |
Referenced in: | [show references] |