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

75
LINES

< > BotCompany Repo | #1034165 // Live WebCam [using sarxos-webcam 0.3.10]

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

Uses 3730K of libraries. Click here for Pure Java version (13877L/72K).

!7

cm LiveWebCam > DynSCP {
  transient WebcamPanel panel;
  int fpsLimit = -1;
  bool autoStart;
  switchable bool alwaysOnTop; // TODO: alwaysOnTop without restart
  
  enhanceFrame {
    minimalFrameSize(f/JInternalFrame, 320, 240);
    internalFramePopupMenuItem(f, "Save to AI Album",
      rThread { dm_saveToAIAlbum(getImage()) });
    internalFramePopupMenuItem(f, "Set FPS...", r {
      final JTextField tf = jtextfield(str(fpsLimit));
      showFormTitled("Set FPS Limit",
        "FPS Limit (-1 for no limit, 0 for no updates):", tf,
        rThread { setFPSLimit(parseInt(gtt(tf))) });
    });
    dm_boolFieldMenuItem(f, 'autoStart);
    internalFramePopupMenuItem(f, "Natural size", r dm_packFrame);
    if (alwaysOnTop) dm_alwaysOnTop(f);
  }

  JComponent visualize2() {
    ret jcenteredbutton("Start", rThread startIt);
  }
  
  afterVisualize { if (autoStart) startIt(); }
  
  void startIt {
    selectWebCam(vf<Webcam> selectCam);
  }
  
  void startPreferredOrSelect {
    selectWebCam_withPreferred(vf<Webcam> selectCam);
  }
  
  void selectCam(Webcam cam) enter {
    final WebcamPanel panel = new WebcamPanel(cam, false);
    LiveWebCam.this.panel = panel;
    bindToComponent(panel, null, r { panel.stop() });
    updateFPSLimitInPanel();
    setComponent(panel);
    //dm_packFrame();
  }
  
  void stopIt {
    if (panel == null) ret;
    panel.stop();
  }
  
  BufferedImage getImage() {
    ret imageFromWebcamPanel(panel);
  }
  
  void setFPSLimit(int limit) {
    setField(fpsLimit := limit);
    updateFPSLimitInPanel();
  }
  
  void updateFPSLimitInPanel {
    setModuleName((fpsLimit >= 0 ? fpsLimit + " FPS - " : "") + "Live WebCam");
    if (panel == null) ret;
    panel.stop();
    if (fpsLimit == 0) ret; // TODO - want to keep last image there anyway
    panel.setFPSDisplayed(fpsLimit < 0);
    if (fpsLimit > 0) panel.setFPSLimit(fpsLimit);
    panel.setFPSLimited(fpsLimit > 0);
    panel.start();
  }
  
  bool isWebCamLive() {
    ret panel != null && fpsLimit != 0;
  }
}

Author comment

Began life as a copy of #1016673

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): bhatertpkbcr, mqqgnosmbjvj

No comments. add comment

-
Snippet ID: #1034165
Snippet name: Live WebCam [using sarxos-webcam 0.3.10]
Eternal ID of this version: #1034165/1
Text MD5: f6d133dde037ac05f31b14c4b57bc12d
Transpilation MD5: c6c7217e078533a2c1c9712dac7648f8
Author: stefan
Category: javax / desktop / camera
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-25 16:43:50
Source code size: 2097 bytes / 75 lines
Pitched / IR pitched: No / No
Views / Downloads: 106 / 159
Referenced in: