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

29
LINES

< > BotCompany Repo | #1009041 // singleImageFromWebcam

JavaX fragment (include) [tags: use-pretranspiled]

Uses 1434K of libraries. Click here for Pure Java version (4731L/26K).

!include once #1013490 // sarxos webcam [include]

// allow camera warm-up (light adjustment)
static double singleImageFromWebcam_delayBeforeShoot = 1;


// take first webcam, open & close
static BufferedImage singleImageFromWebcam() {
  ret singleImageFromWebcam(first(listWebCams()), true);
}

static BufferedImage singleImageFromWebcam(Webcam webcam, bool openAndClose) {
  if (webcam == null) null;
  if (openAndClose) webcam.open(true);
  
  if (singleImageFromWebcam_delayBeforeShoot > 0) {
    print("Camera warm-up (" + formatDouble(singleImageFromWebcam_delayBeforeShoot, 1) + " seconds)");
    sleepSeconds(singleImageFromWebcam_delayBeforeShoot);
  }
  
  try {
    print("Grabbing image");
    BufferedImage img = webcam.getImage();
    print("Got image");
    ret img;
  } finally {
    if (openAndClose) webcam.close();
  }
}

Author comment

Began life as a copy of #1009017

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009041
Snippet name: singleImageFromWebcam
Eternal ID of this version: #1009041/5
Text MD5: 0ea08f45e960b91db1e88d5cb307b541
Transpilation MD5: 962169c208154e5e5b6e32a387e244bf
Author: stefan
Category: javax / desktop / camera
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-25 17:31:31
Source code size: 867 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 482 / 580
Version history: 4 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)