Uses 911K of libraries. Click here for Pure Java version (8607L/44K).
1 | !7 |
2 | |
3 | cmodule VectorImageStream > DynImageSurfaceAndEnabled { |
4 | transient S fpsText; |
5 | transient new PerSecondCounter fpsCounter; |
6 | transient JButton btnStartStream; |
7 | |
8 | start { |
9 | set zoomToWindowOnSetImage; |
10 | dm_vmBus_onMessage_q vectorSDK_gotLine((mod, s) -> handleLine((S) s)); |
11 | dm_doEvery(1.0, r { |
12 | double fps = fpsCounter.getLast(); |
13 | setField(fpsText := formatDoubleX(fps, 1) + " fps"); |
14 | enableButton(btnStartStream, fps == 0); |
15 | }); |
16 | dm_registerAs_direct vectorCamStream(); |
17 | dm_vmBus_onMessageAndNow vectorSDK_connected(rThread startStream); |
18 | } |
19 | |
20 | void handleLine(S s) { |
21 | S prefix = "img: "; |
22 | if (!enabled || !startsWith(s, prefix)) ret; |
23 | fpsCounter.inc(); |
24 | BufferedImage img = imageFromBytes(base64decode(substring(s, prefix))); |
25 | vmBus_send haveVectorImage(module(), img); |
26 | setImage(img); |
27 | } |
28 | |
29 | void startStream enter { |
30 | dm_call vectorSDK('startCamStream); |
31 | } |
32 | |
33 | JPanel makeControlArea() { |
34 | JPanel buttons = super.makeControlArea(); |
35 | enableDoubleBuffering(); // flickers when partially obscured otherwise |
36 | addComponents_inFront(buttons, |
37 | btnStartStream = jbutton("Start", rThread startStream)); |
38 | ret westCenterAndEastWithMargin( |
39 | jbutton("Snapshot", rThread snapshot), |
40 | dm_rightAlignedLabel fpsText(), buttons); |
41 | } |
42 | |
43 | void snapshot enter { |
44 | File f = vectorCamDir("vector-" + ymd_minus_hms_minus_millis() + ".jpg"); |
45 | saveJPEG(f, getImage()); |
46 | copyFileToClipboard(f); |
47 | printFileInfo(f); |
48 | } |
49 | |
50 | // API |
51 | |
52 | BufferedImage getLatestVectorImage() { |
53 | ret getImage(); |
54 | } |
55 | } |
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: | #1027273 |
Snippet name: | Live Vector Cam |
Eternal ID of this version: | #1027273/28 |
Text MD5: | 16a1336bedcf7325c06e0607704eb4fb |
Transpilation MD5: | 3fb1f9a72c57bd7e60816078d04089fe |
Author: | stefan |
Category: | javax / anki vector |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-01 09:44:09 |
Source code size: | 1632 bytes / 55 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 283 / 4162 |
Version history: | 27 change(s) |
Referenced in: | [show references] |