Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

55
LINES

< > BotCompany Repo | #1027273 // Live Vector Cam

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (8607L/44K).

!7

cmodule VectorImageStream > DynImageSurfaceAndEnabled {
  transient S fpsText;
  transient new PerSecondCounter fpsCounter;
  transient JButton btnStartStream;
  
  start {
    set zoomToWindowOnSetImage;
    dm_vmBus_onMessage_q vectorSDK_gotLine((mod, s) -> handleLine((S) s));
    dm_doEvery(1.0, r {
      double fps = fpsCounter.getLast();
      setField(fpsText := formatDoubleX(fps, 1) + " fps");
      enableButton(btnStartStream, fps == 0);
    });
    dm_registerAs_direct vectorCamStream();
    dm_vmBus_onMessageAndNow vectorSDK_connected(rThread startStream);
  }
  
  void handleLine(S s) {
    S prefix = "img: ";
    if (!enabled || !startsWith(s, prefix)) ret;
    fpsCounter.inc();
    BufferedImage img = imageFromBytes(base64decode(substring(s, prefix)));
    vmBus_send haveVectorImage(module(), img);
    setImage(img);
  }
  
  void startStream enter {
    dm_call vectorSDK('startCamStream);
  }
  
  JPanel makeControlArea() {
    JPanel buttons = super.makeControlArea();
    enableDoubleBuffering(); // flickers when partially obscured otherwise
    addComponents_inFront(buttons,
      btnStartStream = jbutton("Start", rThread startStream));
    ret westCenterAndEastWithMargin(
      jbutton("Snapshot", rThread snapshot),
      dm_rightAlignedLabel fpsText(), buttons);
  }
  
  void snapshot enter {
    File f = vectorCamDir("vector-" + ymd_minus_hms_minus_millis() + ".jpg");
    saveJPEG(f, getImage());
    copyFileToClipboard(f);
    printFileInfo(f);
  }
  
  // API
  
  BufferedImage getLatestVectorImage() {
    ret getImage();
  }
}

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: 282 / 4159
Version history: 27 change(s)
Referenced in: